Get BindingSource position based on DataTable string

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

Components are assigned as follows: datatable → bindingsource → datagridview. I want to search for a specific row (based on the primary key) to select it in the grid. I cannot use the bindingsource.Find method because you can use only one column.

I have access to datatable, so I do a manual search in datatable, but how can I get the position of bindingsource strings based on a data row? Or is there another way to solve this?

Im using Visual Studio 2005, VB.NET.

+4
source share
2 answers

Well, I finish the iteration using bindingsource.List and bindingsource.Item. I did not know, but these properties contain data of type datatable using a 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 
0
source

I am trying to add an answer to this two year question. One way to resolve this issue is to add this code after the UpdateAll (SaveItem_Click) method:

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

Then call another UpdateAll method.

0
source

All Articles