Search in datagrid and highligt row in a datagrid when found

I need to have a button that I click that brings up a text box to type in the # I need to find in the datagrid and then when I click search it highlights that row in the the datagrid.  My datagrid is tied to a dataset created in VS.net 2003. How can I do this please.

thanks
running32Asked:
Who is Participating?
 
ElrondCTConnect With a Mentor Commented:
Try something like:

For I as Integer = 0 to DspaBilling1.Count - 1
    If DspaBilling1(I).fldCheck = strSearch Then
        DataGrid1.Select(I)
        Exit For
    End If
Next I
0
 
ElrondCTCommented:
How is your grid tied to the dataset? It's generally easiest to check the data in the underlying data structure rather than in the grid cells. So if you have a DataView as the grid's source, you could do something like this, where dvwData is the DataView bound to grid dgDisplay and strSearch is what you're searching for:

For I as Integer = 0 to dvwData.Count - 1
    If CStr(dvwData(I)("fldCheck")) = strSearch Then
        dgDisplay.Select(I)
        Exit For
    End If
Next I
0
 
running32Author Commented:
I have my datagrid tied to a dataset how can I chagne it.

billingcount = SqlDataAdapter4.Fill(DspaBilling1)
            DataGrid1.DataSource = DspaBilling1
            DataGrid1.DataMember = "tblPAVoucher"
            'frmloading.Hide()
            Dim tablestyle As New DataGridTableStyle
            tablestyle.MappingName = DspaBilling1.Tables(0).TableName
0
 
running32Author Commented:
I get the error DspaBilling1(I).fldCheck  cannot be indexed because i has not default property.  Thanks
0
 
ElrondCTCommented:
"fldCheck" is just a placeholder. You'll have to put in the name of your actual field that you want to check against. Likewise, you need to replace "strSearch" with whatever value you want to look for. I don't know what those actual variable names are because you haven't posted that information.

However, I don't know why you'd get an error that it can't be indexed. Nothing in the code I provided has anything to do with indexing. Perhaps you should post your code (just the section where there's a problem), and flag which line is active when you get the error.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.