DataGridView question

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

How can you tell is an "item" exists in a specific column of a DataGridView
?

In a list box you could go...

If ListBox1.Items.Contains(strWhatever) then

How is this accomplshed using a DataGridView ?
 
Rob,

You will have to use the Find function on the BindingSource (assuming you
are databound) or enumerate each row/cell and look for your value.

For the binding source, try:

Dim view1 As New DataView(tables(0))

' Create a DataGridView control and add it to the form.
Dim datagridview1 As New DataGridView()
datagridview1.AutoGenerateColumns = True
Me.Controls.Add(datagridview1)

' Create a BindingSource and set its DataSource property to
' the DataView.
Dim source1 As New BindingSource()
source1.DataSource = view1

' Set the data source for the DataGridView.
datagridview1.DataSource = source1

' Set the Position property to the results of the Find method.
Dim itemFound As Integer = source1.Find("artist", "Natalie Merchant")
source1.Position = itemFound

From MSDN: https://msdn2.microsoft.com/en-us/library/ms158165.aspx

Hope this helps,


Steve
 
Back
Top