2017-05-17 45 views
0

快速的问题或者我希望它很快。将DataGridView1添加到Listbox1 VB.net

我有一个DataGridView1与4列,我想将DataGridView1上的所有内容添加到列表框。

列举例

Name Average Handicap Paid 
John 170  0   20 
Alex 180  0   15 
Jane 200  0   10 
Jim  150  0   20 

当我点击Button1的,我想它去的路线,并将它们添加到ListBox1的

ListBox1的实例

John Paid $20 
Alex Paid $15 
Jane Paid $10 
Jim Paid $20 

我DataGridView1设置,如果你点击它,它会填充一些标签,并希望有一种方法可以自动选择每行一个,只需将Labels.text信息作为它的自动sc滚动列表,但不知道如何自动选择一个列表。

谢谢

+1

您将循环遍历网格的行,并执行相同的操作,以填充“标签”以获取您添加到“列表框”中的值。标签本身不起作用。你应该有一个方法,你可以传递一个网格行并取回值,然后在填充'Label'和'ListBox'时调用该方法。 – jmcilhinney

回答

0

Button1 click事件...

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 
    For i As Integer = 0 To DataGridView1.Rows.Count - 1 
     Dim LboxValue As String = DataGridView1.Rows(i).Cells(0).Value & " " & DataGridView1.Columns(3).HeaderText & " " & DataGridView1.Rows(i).Cells(3).Value 
     ListBox1.Items.Add(LboxValue) 
    Next 
End Sub 

根据自己的需要...

enter image description here

希望它能帮助。

+0

我有类似的东西,但(我)给了我一个错误,说它已经超出了限制或者这个影响。我想我缺少的是作为System.EventArgs的 。 这工作谢谢你! –