Data Grid Selection

vellaima

Centurion
Joined
Jan 29, 2003
Messages
109
Visual Basic:
Dim dr() As DataRow
Dim i As Integer
dr = SalesRep1.Tables("sales_representative").Select("ID = '" + searchtxt.Text + "'")
For i = 0 To UBound(dr)
   MsgBox((dr(i)("Name")))
Next

In the above program if the user enters the sales_representative id it will search the SalesRep1 DataSet and display the name of the Sales Representative in Message Box. This is what I have done. It works perfectly.

I am displaying the Sales Representative Details in the DataGrid in form1 . There is also a search button in the bottom of the form1. Once the search button is clicked the above program gets triggered.

If the Sales_representative ID is available in the DataSet then I would like to highlight the details of the particular row in DataGrid say in red color.

Can we achieve this.
 
You may have to do manually looping to do this.

You could try something like:
Visual Basic:
Dim i As Long
For i = 0 To SalesRep1.Tables("sales_representative").Rows.Count - 1
    If (SalesRep1.Tables("sales_representative").Rows(i)("ID").ToSTring() = searchtxt.Text) Then
        gridControl1.Select(i)
    End If
Next

I'm not sure how you select a row in the grid offhand, but I think it's just Select (might be SelectRow?).

-nerseus
 
Thanks for providing me with this code. It worked perfectly. I also added another line.

Visual Basic:
If (SalesRep1.Tables("sales_representative").Rows(i)("ID").ToSTring() = searchtxt.Text) Then
        gridControl1.currentRowIndex(i)
        gridControl1.Select(i)
    End If

I have one query though. Whenever i enter the "id" to search it is not deselecting the previous one. How can we avoid multiple selection in grid. Can anyone please tell me how to resolve this. It will be very helpful.
 
Back
Top