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!

DataGrid Click Event 4

Status
Not open for further replies.

isha

MIS
Mar 7, 2002
216
0
0
IN
I used the datagrid click event to show the values in a particular row of the datagrid in text boxes below the grid.
But the problem is I have to double click the row where as i have used the single click event.
Can someone provide me a hint.
 
Use the RowColChange event instead, and this will fire when the user uses the ARROWS or TAB to move to another row/column (depending what the grid's tab navigation property is set to)
 
If you work with a database, you can use something like this:

Dim cell1 as String

Private Sub DataGrid1_SelChange(Cancel As Integer)
DataGrid1.Col = 0
cell1 = DataGrid1.Columns(DataGrid1.Col).Value

search_data (cell1)
End Sub

Public Sub search_data(data As String)

rst.Open "select * from
where [record_cell] = '" & data _ & "'", cnn, adOpenDynamic, adLockOptimistic

' now put the data into the textfields

End Sub

Hope this helps... play a bit around with this code, I did the same and it works.

Greetz!
 

>If you work with a database

Then you should already have a recordset with the records used to fill the grid with and can do a search with-in that same recordset using the FIND method, and get the data from there.
(unless you are doing Paging)

Also, you could just take the cell values from the grid.

Another method, my favorite, is to use the recordset's bookmark property to locate the selected record.
And even this can be done automatically so that the movement in the grid keeps the recordset in sync. No FINDs/Searches needed at all.


 
thnx CCLINT, I wish I knew that when I was having these problems with the Datagrid :). At least now I know, so next time it will be much easier.

Thnx!
 

Here's a tip for HFlex grid users who fill the grid with records from a recordset using the ADO client cursor manager:

When filling the grid, while looping through the recordset, (or, if you used the DataSource or Recordset property of the grid in order to automatically fill it, you will need to make an initial loop through all grid rows), set the flex grid's RowData property to the Recordset's BookMark property.

Then in the RowColChange event, use something like:

If Val(.RowData(.Row)) > 0 Then m_rsADO.Bookmark = CDbl(.RowData(.Row))

Now the recordset should stay in sync when navigating in the grid.

To do this the other way around, when the recordset is repositioned, you can use then recordset's absolute position property and add this the the row number of the first row with a record (eliminating header rows) and call the grid's Row method.
Declaring the recordset using WithEvents also helps, because you can the reposition the grid from the recordset's MoveComplete event with one or two lines of code.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top