?
Solved

get column data from selected row vb.net

Posted on 2016-09-19
8
Medium Priority
?
36 Views
Last Modified: 2016-09-19
I have this code that gets the count of selected rows ok but I want the string of whats shown on the attached as opposed to the index number of the row. not sure how to do that.

[code][code]
    Private Sub PanelLinkShort_Click(sender As Object, e As EventArgs) Handles PanelLinkShort.Click


        Dim selectedRowCount As Integer =
           DataGridViewStringsBulk.Rows.GetRowCount(DataGridViewElementStates.Selected)
        Dim x As String
        If selectedRowCount > 0 Then

            Dim i As Integer
            For i = 0 To selectedRowCount - 1

                'get rows
                x = DataGridViewStringsBulk.SelectedRows(i).Index.ToString()


            Next i


            MessageBox.Show("Finished")

        End If

    End Sub

Open in new window

[/code][/code]

ex
0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 41804660
Could it be:

x = DataGridViewStringsBulk.SelectedRows(i)("CertainColumn").Value

Open in new window

0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41804663
thank you
0
 

Author Comment

by:PeterBaileyUk
ID: 41804664
should it have a dot between?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PeterBaileyUk
ID: 41804666
this part is underlined red: DataGridViewStringsBulk.SelectedRows(i)
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41804671
what do you mean? I have copied the name of your control from your code so it should be good? Where have you placed the new line of code? Inside your loop I hope! What is the error message that you get?
0
 

Author Comment

by:PeterBaileyUk
ID: 41804681
it says it cannot be indexed because datagridviewrow has no default property

      If selectedRowCount > 0 Then

            Dim i As Integer
            For i = 0 To selectedRowCount - 1

                'get rows


                x = DataGridViewStringsBulk.SelectedRows(i)("Strshort").Value
            Next i


            MessageBox.Show("Finished")

        End If

Open in new window

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41804693
replace it with :
x = DataGridViewStringsBulk.SelectedRows(i).Cells("Strshort").Value

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 41804702
yes that got it.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question