Re: Populating list box from database problems

Unless you do some serious binding you would need to make a direct DB hit (the non-query-execute) kind where you use a SQL DELETE statement.. and feed it the key for the row you want to delete.

I want to delete all of the rows in the db, but on a separate button press. For now this code is simply returning what was captured at the time. Any new database additions are not reflected in the listbox when the code is executed

Re: Populating list box from database problems

Posted 09 January 2014 - 08:31 AM

After taking a break from this and coming back last night, this morning the application is finally starting to come together. I fixed and cleaned up some things. I would greatly appreciate you guys' insight on why these problems are creeping up. Final problems I'm trying to resolve include:

Clear button doesn't work after Retrieve button populates ListBox1. Error = Items collection cannot be modified when the DataSource property is set. I understand this error, but am not sure how to go about correcting it

ListBox1 double click event doesn't work after Retrieve button populates the list. The list was supposed to be populated, then an operation could be double clicked and it would send the first and second number to the corresponding text boxes. This event does work as long as the Retrieve button is never used.

Save to DB button doesn't work after Retrieve button is used. Error = "Conversion from type DataRowView to type String is not valid"

I think fixing the clear button might resolve a lot of the issues, but still won't help with the ListBox1 double click event not working after a retrieval.

Re: Populating list box from database problems

If your listbox1 is being backed by a dataset perhaps - add the value to the dataset and NOT to the items list. Those are two different things. Yes.. this means you'll probably need your dataset to be a global variable.

Quote

Clear button doesn't work after Retrieve button populates ListBox1. Error = Items collection cannot be modified when the DataSource property is set. I understand this error, but am not sure how to go about correcting it

Same thing as above - you need to clear the dataset. So, again, have the dataset be a global variable and interact with it that way.

Quote

ListBox1 double click event doesn't work after Retrieve button populates the list. The list was supposed to be populated, then an operation could be double clicked and it would send the first and second number to the corresponding text boxes. This event does work as long as the Retrieve button is never used.

Same as above - you are interacting with the wrong thing.

Quote

Save to DB button doesn't work after Retrieve button is used. Error = "Conversion from type DataRowView to type String is not valid"

Private Sub cmdInsertData_Click(sender As Object, e As EventArgs) Handles cmdInsertData.Click
Dim x As Integer
For x = 0 To ListBox1.Items.Count - 1
If ListBox1.GetSelected(x) = False Then
ListBox1.SetSelected(x, True)
End If
Next
Try
For Each Operation As String In ListBox1.SelectedItems
Call Module2.InsertData()
Next
Catch ex As Exception
MessageBox.Show("Problem:" & Environment.NewLine & ex.Message)
End Try
End Sub