M
Max
I am writing windows application in vb.net and I have scenario where I
have two listboxes side by side and I want to "copy" selected items in
listbox on the left to the one on the right. Both listboxes bound to
two different dataviews like this:
vueToStudents.Table = dsStudents.Tables("Students")
vueToStudents.RowFilter = "SchoolID = 'R39'"
vueToStudents.Sort = "LastName"
listToStudents.DataSource = vueToStudents
listToStudents.DisplayMember = "StudentName"
listToStudents.ValueMember = "StudentID"
Ok now I want to add a row to vueToStudents (eventually rows would
need to come from vueFromStudents which is bounded to a
listFromStudents but to simplify my problem I did the following)
Private Sub btnAddRow(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddRow.Click
Dim row As DataRowView = vueToStudents.AddNew()
row("SchoolID") = "R39"
row("StudentID") = "123456"
row("FirstName") = "John"
row("LastName") = "Smith"
row.EndEdit()
End Sub
This works kind of like I expect. It adds a row to a listToStudents
(since it's bounded to vueToStudents) but this new row is just a
selected blank row.
Now if I click on a button btnAddRow again it "changes" the blank row
to the one with information above and it adds another blank row.
What do I need to do so that when I click on a button a row is
displayed with information that I added and not as blank? I tried to
rebind listToStudents to vueToStudents right after adding a row but
that didn't help. The correct row is displayed only after I click on a
button for a second time (when the form is reloaded). I'd appreciate
any help to this problem. Thank you.
have two listboxes side by side and I want to "copy" selected items in
listbox on the left to the one on the right. Both listboxes bound to
two different dataviews like this:
vueToStudents.Table = dsStudents.Tables("Students")
vueToStudents.RowFilter = "SchoolID = 'R39'"
vueToStudents.Sort = "LastName"
listToStudents.DataSource = vueToStudents
listToStudents.DisplayMember = "StudentName"
listToStudents.ValueMember = "StudentID"
Ok now I want to add a row to vueToStudents (eventually rows would
need to come from vueFromStudents which is bounded to a
listFromStudents but to simplify my problem I did the following)
Private Sub btnAddRow(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddRow.Click
Dim row As DataRowView = vueToStudents.AddNew()
row("SchoolID") = "R39"
row("StudentID") = "123456"
row("FirstName") = "John"
row("LastName") = "Smith"
row.EndEdit()
End Sub
This works kind of like I expect. It adds a row to a listToStudents
(since it's bounded to vueToStudents) but this new row is just a
selected blank row.
Now if I click on a button btnAddRow again it "changes" the blank row
to the one with information above and it adds another blank row.
What do I need to do so that when I click on a button a row is
displayed with information that I added and not as blank? I tried to
rebind listToStudents to vueToStudents right after adding a row but
that didn't help. The correct row is displayed only after I click on a
button for a second time (when the form is reloaded). I'd appreciate
any help to this problem. Thank you.