Chose three rows from database for comparation

topsykretts

Well-known member
Joined
Dec 22, 2011
Messages
47
Programming Experience
Beginner
Here I am again my friends. Here is a code which simply send value from first cell of selected row into 1 of 3 textboxes.
VB.NET:
        If RadioButton1.Checked Then
            TextBox1.Text = Me.DataGridView1.SelectedRows(0).Cells(0).Value
        ElseIf RadioButton2.Checked Then
            TextBox2.Text = Me.DataGridView1.SelectedRows(0).Cells(0).Value 
        ElseIf RadioButton3.Checked Then
            TextBox3.Text = Me.DataGridView1.SelectedRows(0).Cells(0).Value
        End If

Using value from textbox I need to locate same row and get a value from the same row but other column. I used filter on BindingSource as solution.

VB.NET:
'FC-First Column from database
'SC-SecondCell

Dim SC as String

Table1BindingSource.Filter = "FC LIKE '%" & TextBox1.Text & "%'"
        SC = Me.DataGridView1.SelectedRows(0).Cells(1).Value
        TextBox4.Text = SC
Table1BindingSource.Filter = "FC LIKE '%" & TextBox2.Text & "%'"
        SC = Me.DataGridView1.SelectedRows(0).Cells(1).Value
        TextBox5.Text = SC
Table1BindingSource.Filter = "FC LIKE '%" & TextBox3.Text & "%'"
        SC = Me.DataGridView1.SelectedRows(0).Cells(1).Value
        TextBox6.Text = SC

Now values are stored and I will do something with them after, but I need to refresh datagridview because last operation of search filter is saved on screen.
This 3 chosen rows are actually 3 different kind of material and I need to compare their properties and continue with calculation.

Probably there is another way to chose 3 materials(from database),save them and after in future to call their properties. If you have some advice, they are welcome.
Thanks in advance.
 
There's no need to filter a BindingSource. If you're using a BindingSource then you simply get the selected record from its Current property as a DataRowView and get all the field values from that. You don't touch the grid at all. The whole point of using a BindingSource is that it is the one and only source for all things related to the bound data.
 
There's no need to filter a BindingSource. If you're using a BindingSource then you simply get the selected record from its Current property as a DataRowView and get all the field values from that. You don't touch the grid at all. The whole point of using a BindingSource is that it is the one and only source for all things related to the bound data.

How to get selected record as DataRowView?
 
Back
Top