Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem related to msflexgrid!!!

Status
Not open for further replies.

nitika

Programmer
Mar 22, 2002
21
0
0
IN
Hi

I have one problem related to msflexgrid.How can we select multiple records in a msflexgrid.
Suppose the user is selecting multiple values in a msflexgrid, then how can we capture those selections in the coding so that we can further use it.

Plz tell me the solution.
Though i am able to select a range of records but is there any other way so that i can select the recordsbu tnot all lying adjacently. Means they may be separated in grid itself.
Say first i select the first record & then 4th record 7 then 7th & so on.

Is there any solution.

Thanx in advance

 
I would probably keep the selection information is a separate structure, perhaps as simple as a boolean array with the same number of elements as rows in the grid, then as the records are selected, set the corresponding elements in the array to True, and upon unselecting (or processing depending on your application) a record, set to False.

Then you can loop thru the array, processing those grid records where the corresponding array element is True.

Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
CajunCenturion is right. MSFlexgrid does not have built in capabilities to make multiple non-adjacent selection. For adjacent properties - Row and Rowsel - give boundaries for selected rows ( where Row maybe greater, equal to, or less than Rowsel ). You will need indeed to create a separate structure to hold that info. You might need also to highlight selected rows ( you will need to write custom code to highlight non-consecutive rows). Having a separate array ( or any other structure) for this might work, but there are few things to think about. Let's say you have an array or any other structure in which elements correspond to an ordinal number of a row in the grid. If you delete rows or add rows to the middle of the grid , you will need to write code to take that into account. If you sort MSFlexgrid, then, most likely, you will not be able to adjust you array data correspondingly. Since in my software I sort MSFlexgrid rows, I use CellBackColor property for this purpose. I just go through all rows and check CellBackColor property of first column in each row ( since I always highlight the whole row). I use system color vbHighlight for that. The largest grid that I have to deal with in this manner has 2000 rows ,so that the code runs pretty fast even on slow machines. Of course, if you have a lot of rows, checking CellBackColor property of each row might be rather time consuming. Anyway, if you do not sort your Flexgrid , which is probably the case, use array thing just account for deletions and insertions.
 
Hi Friends,
Thanx for reply.
I have one more question. How can I delete a specific record in a msflexrid by pressing the delete key only.
will i have to use some API call for that or otherwise it is possible. Just tell me.


Nitika


 
It depends on how you populate the grid. If you populate the grid using dao then you can use the dao functions to delete the selected record.
For example:

Private Sub cmdDeleterow_Click()
If Adodc1.Recordset.Supports(adDelete) Then
Adodc1.Recordset.Delete
Call SafeMoveBack
Adodc1.Recordset.Requery
Else
MsgBox "Record Not Deleted"
End If
End Sub

Private Sub SafeMoveBack()
With Adodc1.Recordset
If Not .BOF Then
.MovePrevious
If .EOF Then
.MoveNext
End If
End If
End With
End Sub

You have a choice of using the delete key to delete the selected row. If you go this route you can trap on the key press event to see when the "Delete" key was pressed.
Other solution can be is to add a command button and then delete from there. Its caption could be delete selected row, perhaps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top