Solved

get column data from selected row vb.net

Posted on 2016-09-19
8
27 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
  • 5
  • 3
8 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 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
 

Author Comment

by:PeterBaileyUk
ID: 41804666
this part is underlined red: DataGridViewStringsBulk.SelectedRows(i)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 69

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 69

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now