[2005] List Box Up/Down and Updates
I have 3 list boxes.
1 contains every report that is in a sql database.
The other contains Reports for the specific types of Correspondence (which is the 3rd listbox).
1 Box for different types of Correspondence.
1 Containing Every Report.
1 Containing the Selected Reports for the given Correspondence.
These are all Bound.
My problem is that the 3rd list box. Which is the one that contains the selected reports for the different correspondence. Will not let me change the order of the list. Moving items up and down the list because they are sorted by a 'print_order'. My only goal in this project is for the user to be able to change the print order of these reports. But they can't have the same print order.
Is there anyway to load this list, then get rid of the bindings, change the order then click a save button that will recognize the order the list is in and set that as the print_order?
This is very hard to explain, but I can't figure this out.
EDIT: The error message I get is, "Can't edit listbox when the dataSource is set" What is the best meaning easiest way to fix this.
Re: [2005] List Box Up/Down and Updates
try setting the datasource to null before running the change events?
are you wanting to write the changes of the order back to the database?
Maybe yous et the sortorder of the datatable being displayed to a temp datatable, load the temp datatable to the source instead of the actual datatable from the database?
Re: [2005] List Box Up/Down and Updates
Yes I'm wanting to save the changes in the order back to the database
Re: [2005] List Box Up/Down and Updates
oh, also bind the list box you want to order to a temp datatable that you make in code. have to do some sort of late binding instead of at design time.
vb Code:
Dim dt As New DataTable
Dim strSQL As String = "Select Code,Description From MyTable"
Dim Connection As New OleDbConnection("PROVIDER=....")
Dim DA As New OleDbDataAdapter(strSQL, Connection)
Dim DS As New DataSet
private sub buildtable()
dt.Columns.Add("DocumentName", GetType(System.String))
dt.Columns.Add("DocumentOrderId", GetType(System.Integer))
'
' Populate the DataTable to bind to the Combobox.
'
Dim drDSRow As DataRow
Dim drNewRow As DataRow
'fill dataset based on info from your database table documentName
For Each drDSRow In DS.Tables("DocumentName").Rows()
drNewRow = dt.NewRow()
drNewRow("DocumentName") = drDSRow("DocumentName")
drNewRow("DocumentOrderId") = drDSRow("DocumentOrderId")
dt.Rows.Add(drNewRow)
Next
end sub
Private sub form_load( yadda yadda)
DA.Fill(DS, "Documents")
buildtable()
'now we just filled the unbound datatable with info from the database,
' let's fill the listbox
With ListBox1
.DataSource = dt
.DisplayMember = "DocumentName"
.ValueMember = "DocumentOrderId"
.SelectedIndex = 0
End With
'now you should be able to move the sort order around since the listbox
'is actually unbound. I'm sure you have sort code made already, but
'now it's just a matter of calling the original document information
'from the database based on the users selection from the unbound
'listbox
Re: [2005] List Box Up/Down and Updates
So what you're saying is I build a table in code that is unbound at run time, i fill it from my database table. Then once it's filled I bind my listbox to it edit whatever i need then push that table back to the database?
Re: [2005] List Box Up/Down and Updates
actually, don't bind your listbox to the table you built in code, just loop through the items and add each item to an unbound listbox.
Re: [2005] List Box Up/Down and Updates
oh so just loop through the table and the ones that go to the selected correspondence just add them to the listbox? Then I can edit and push them to the table. That's nice if i get you right.
Re: [2005] List Box Up/Down and Updates
What you should be doing here is using BindingSources. You can bind the same DataTable to three different BindingSource objects and then sort and filter each one independently. Each ListBox is then bound to a different BindingSource.