Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim lvt As ListViewItem
        If dataGrid2.SelectedRows.Count >= 0 Then

            For Each row As DataGridViewRow In dataGrid2.SelectedRows
                lvt = New ListViewItem()
                lvt.SubItems.Add(row.Cells(1).Value.ToString())
                lvt.SubItems.Add(row.Cells(2).Value.ToString())
                bookList.Items.Add(lvt)
            Next

        Else
            MsgBox("Select a Book!", MsgBoxStyle.Exclamation, "Warning")
        End If


    End Sub
Posted
Comments
Michael Portanoba 17-Oct-12 0:56am    
my code wont work.. after i press Add button, nothing happens

VB
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click



        If dataGrid2.SelectedCells.Count >= 0 Then

            For Each row As DataGridViewRow In dataGrid2.SelectedRows

                bookList.Items.Add(row.Cells(1).Value.ToString())
                bookList.Items.Add(row.Cells(2).Value.ToString())

            Next

        Else

            MsgBox("Select a Book!", MsgBoxStyle.Exclamation, "Warning")

        End If
 
Share this answer
 
Comments
Aarti Meswania 18-Oct-12 1:07am    
try this
bookList.Items.Add(row.Cells(1).Value.ToString() & " (" & row.Cells(2).Value.ToString() & ")")
I have only this idea show author name in brackets
Michael Portanoba 18-Oct-12 1:11am    
Alright!! thanks.. :D very much.. it worked fine..
Aarti Meswania 18-Oct-12 1:13am    
welcome
SQL
For Each row As DataGridViewRow In dataGrid2.SelectedRows
  bookList.Items.Add(row.Cells(1).Value.ToString(),row.Cells(2).Value.ToString(),0)
Next

Happy Coding!
:)
 
Share this answer
 
v3
Comments
Michael Portanoba 17-Oct-12 1:29am    
thank you for the answer. but i cant seem to understand that it has blue underline on the code bookList.Items.Add(row.Cells(1).Value.ToString(),row.Cells(2).Value.ToString(),Nothing)
Aarti Meswania 17-Oct-12 1:30am    
please see updated solution
Michael Portanoba 17-Oct-12 1:33am    
yes it has an error and this is what it says. ( Overload resolution failed because no accessible 'Add' is most specific for these arguments:
'Public Overridable Function Add(key As String, text As String, imageIndex As Integer) As System.Windows.Forms.ListViewItem': Not most specific.)
'Public Overridable Function Add(key As String, text As String, imageKey As String) As System.Windows.Forms.ListViewItem': Not most specific.
Aarti Meswania 17-Oct-12 1:34am    
please see updated solution write
0 instead of Nothing
Michael Portanoba 17-Oct-12 1:38am    
alright!! thanks Aarti Meswania it works fine now! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900