• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

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
0
running32
Asked:
running32
  • 3
  • 2
1 Solution
 
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
 
ElrondCTCommented:
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now