Avatar of Mark Bakelaar
Mark BakelaarFlag for Norway asked on

Conversion selected row in datagridview to selected row in datatable

Hi Experts,
I have 4 tabpages with a datagridview on them. In each datagridview is a part of a datatable displayed. On each tabpage are also labels displayed (representing 4 compartments). When a user selects a label of one of these compartments a check is made if this label matches the compartment of the selected datagridline.
The problem is that I can check which datagridviewline is selected (selectedASNline), but if I use this value it seems that this value is not the selectedrow of the datatable. How can I convert the selectedrow of the datagridview to the selectedrow on of the datatable?
Any help is appreciated, MB
Dim SelectedASNLine, i As Integer
        Dim CompartmentArea As Label = sender
        'Find the correct datagridview based on the name of the label (sender)
        If CInt(CompartmentArea.Name.Substring(0, 1)) = 1 Then
            SelectedASNLine = Me.DataGridView3.CurrentRow().Index
        ElseIf CInt(CompartmentArea.Name.Substring(0, 1)) = 2 Then
            SelectedASNLine = Me.DataGridView4.CurrentRow().Index
        ElseIf CInt(CompartmentArea.Name.Substring(0, 1)) = 3 Then
            SelectedASNLine = Me.DataGridView5.CurrentRow().Index
            SelectedASNLine = Me.DataGridView6.CurrentRow().Index
        End If
        'Check if the selected compartmentarea and the compartment in ASN match
        If Not ds.Tables("ASNs").Rows(SelectedASNLine)("Compartment").ToString = (CompartmentArea.Name.Substring(0, 2)).ToString Then
            MsgBox("This ASN line is stored in another compartment", MsgBoxStyle.Information)
            Exit Sub
        End If

Open in new window

Visual Basic.NETVisual Basic Classic

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mark Bakelaar

Roger, I got it to work. Thanks again...


Do you have a solution for datagridviews with multiple row selection enabled?

How do i get to all the selected rows from a dataset throw a datagridview
Your help has saved me hundreds of hours of internet surfing.