4

I have a datatable that contains the rows of a database table. This table has a primary key formed by 2 columns.

The components are assigned this way: datatable -> bindingsource -> datagridview. What I want is to search a specific row (based on the primary key) to select it on the grid. I cant use the bindingsource.Find method because you only can use one column.

I have access to the datatable, so I do manually search on the datatable, but how can I get bindingsource row position based on the datatable row? Or there is another way to solve this?

Im using Visual Studio 2005, VB.NET.

Ronald
  • 41
  • 1
  • 2
  • Create an extension method on a bindingsource. Works like a charm http://stackoverflow.com/questions/1767018/bindingsource-find-multiple-columns/1767100#comment9650142_1767100 – Martin Nov 07 '11 at 14:45
  • I think this guy had the same requirement: http://bytes.com/topic/visual-basic-net/answers/841559-bindingsource-find-multiple-primary-keys – Tim Schmelter Aug 30 '10 at 16:20

2 Answers2

2

I am attempting to add an answer for this 2-year old question. One way to solve this is by appending this code after the UpdateAll method(of SaveItem_Click):

Me.YourDataSet.Tables("YourTable").Rows(YourBindingSource.Position).Item("YourColumn") = "YourNewValue"

Then call another UpdateAll method.

Arman
  • 1,434
  • 2
  • 22
  • 42
0

Well, I end up iterating using bindingsource.List and bindingsource.Item. I didnt know but these properties contains the data of the datatable applying the filter and sorting.

Dim value1 As String = "Juan"
Dim value2 As String = "Perez"
For i As Integer = 0 To bsData.Count - 1
    Dim row As DataRowView = bsData.Item(i)
    If row("Column1") = value1 AndAlso row("Column2") = value2 Then
        bsData.Position = i
        Return
    End If
Next
Ronald
  • 41
  • 1
  • 2