Listbox data to another form - data table?
Have have a listbox in my main form. I need to transfer that data to another form to use in a SQL command. I'm not sure how to go about doing this. Is a data table to most efficient way?
Right now I have code that transfers my main listbox data on form1 to another listbox on form2 - which works fine. The problem is the user doesn't need a listbox on form2.
Code:
For i As Integer = 0 To Form1.ProductListBox.Items.Count - 1
Me.ListBox1.Items.Add(CStr(Form1.ProductListBox.Items(i).Item(0)))
Next
Any help would greatly appreciated.
Re: Listbox data to another form - data table?
If your moving the data around, it would be better to store it as a table and consult that table as and when needed.
But if you want to retain the data in the ListBox on Form1, you can access the contents directly in Form2, just by referring to it using Form1.ListBox1.Items(n) as necessary.
Re: Listbox data to another form - data table?
Why not create a DataTable in the first place and simply bind it to the ListBox? Now you just have to pass the existing DataTable to the other form, or perhaps the other form already could have a reference to it anyway.