Solved

get column data from selected row vb.net

Posted on 2016-09-19
8
33 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 70

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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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