Victor Charles
asked on
Help with selecting multiplr rows from listbox control using VB.NET
Hi,
I loaded my listbox control from an xml file, when i use the code below to select mutiple rows, I receive the following error:
Operator '+' is not defined for string "," and type 'DataRowView'.
On line:
tempstring += "," + item
The error does not occur if I add the countries in the items collection of the listbox control, but I need to load the control from the xml file.
How di i fix this problem?
Private Sub ListBox1_Click(sender As Object, e As System.EventArgs) Handles ListBox1.Click
tempstring = ""
For Each item As Object In Me.ListBox1.SelectedItems
tempstring += "," + item
Next
If tempstring <> "" Then
tempstring = Microsoft.VisualBasic.Righ t(tempstri ng, Len(tempstring) - 1)
End If
Me.C1TrueDBGrid45.Columns( "Receiver" ).Text = tempstring
End Sub
Code to load listbox from Form load event.
fsReceiver1 = New System.IO.FileStream(Appli cation.Sta rtupPath + "\Receiver.xml", IO.FileMode.Open)
dtsetReceiver.Clear()
dtsetReceiver.ReadXml(fsRe ceiver1)
fsReceiver1.Close()
Me.ListBox1.DataSource = dtsetReceiver.Tables(0)
Me.ListBox1.DisplayMember = "Receiver"
Thanks,
Victor
I loaded my listbox control from an xml file, when i use the code below to select mutiple rows, I receive the following error:
Operator '+' is not defined for string "," and type 'DataRowView'.
On line:
tempstring += "," + item
The error does not occur if I add the countries in the items collection of the listbox control, but I need to load the control from the xml file.
How di i fix this problem?
Private Sub ListBox1_Click(sender As Object, e As System.EventArgs) Handles ListBox1.Click
tempstring = ""
For Each item As Object In Me.ListBox1.SelectedItems
tempstring += "," + item
Next
If tempstring <> "" Then
tempstring = Microsoft.VisualBasic.Righ
End If
Me.C1TrueDBGrid45.Columns(
End Sub
Code to load listbox from Form load event.
fsReceiver1 = New System.IO.FileStream(Appli
dtsetReceiver.Clear()
dtsetReceiver.ReadXml(fsRe
fsReceiver1.Close()
Me.ListBox1.DataSource = dtsetReceiver.Tables(0)
Me.ListBox1.DisplayMember = "Receiver"
Thanks,
Victor
Try tempstring = tempstring & "," & item, instead of tempstring += "," + item
I'm guessing you've bound your listbox to something that is returning a DataTable. When you are trying to append, you are trying to append a DataRowView object, rather than the text within the field being displayed.
You probably need something more like:
You probably need something more like:
tempstring &= "," & item.Item("NameOfColumn").ToString()
ASKER
Hi,
Unfortunately both approaches did not work, when I tried the first solution I received the following error:
Operator '&' is not defined for string "," and type 'DataRowView'.
When I tried the last approach(tempstring &= "," & item.Item("Receiver").ToSt ring()
) in the code below, for some reason, all the rows in the Grid dissapear when I select a row from the listbox. Any ideas why the rows in the Grid dissapears?
Private Sub ListBox1_Click(sender As Object, e As System.EventArgs) Handles ListBox1.Click
tempstring = ""
For Each item As Object In Me.ListBox1.SelectedItems
tempstring &= "," & item.Item("Receiver").ToSt ring()
Next
If tempstring <> "" Then
tempstring = Microsoft.VisualBasic.Righ t(tempstri ng, Len(tempstring) - 1)
End If
Me.C1TrueDBGrid45.Columns( "Receiver" ).Text = tempstring
End Sub
Thanks.
V.
Unfortunately both approaches did not work, when I tried the first solution I received the following error:
Operator '&' is not defined for string "," and type 'DataRowView'.
When I tried the last approach(tempstring &= "," & item.Item("Receiver").ToSt
) in the code below, for some reason, all the rows in the Grid dissapear when I select a row from the listbox. Any ideas why the rows in the Grid dissapears?
Private Sub ListBox1_Click(sender As Object, e As System.EventArgs) Handles ListBox1.Click
tempstring = ""
For Each item As Object In Me.ListBox1.SelectedItems
tempstring &= "," & item.Item("Receiver").ToSt
Next
If tempstring <> "" Then
tempstring = Microsoft.VisualBasic.Righ
End If
Me.C1TrueDBGrid45.Columns(
End Sub
Thanks.
V.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.