Results 1 to 8 of 8

Thread: [2005] List Box Up/Down and Updates

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    [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.
    Last edited by tuber; Dec 17th, 2007 at 03:52 PM.
    Tuber

    "I don't know the rules"

  2. #2
    Lively Member RickyH's Avatar
    Join Date
    Oct 2007
    Posts
    92

    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?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] List Box Up/Down and Updates

    Yes I'm wanting to save the changes in the order back to the database
    Tuber

    "I don't know the rules"

  4. #4
    Lively Member RickyH's Avatar
    Join Date
    Oct 2007
    Posts
    92

    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:
    1. Dim dt As New DataTable
    2. Dim strSQL As String = "Select Code,Description From MyTable"
    3. Dim Connection As New OleDbConnection("PROVIDER=....")
    4. Dim DA As New OleDbDataAdapter(strSQL, Connection)
    5. Dim DS As New DataSet
    6.  
    7.    
    8. private sub buildtable()
    9.     dt.Columns.Add("DocumentName", GetType(System.String))
    10.     dt.Columns.Add("DocumentOrderId", GetType(System.Integer))
    11.     '
    12.     ' Populate the DataTable to bind to the Combobox.
    13.     '
    14.     Dim drDSRow As DataRow
    15.     Dim drNewRow As DataRow
    16.  
    17. 'fill dataset based on info from your database table documentName
    18.     For Each drDSRow In DS.Tables("DocumentName").Rows()
    19.         drNewRow = dt.NewRow()
    20.         drNewRow("DocumentName") = drDSRow("DocumentName")
    21.         drNewRow("DocumentOrderId") = drDSRow("DocumentOrderId")
    22.         dt.Rows.Add(drNewRow)
    23.     Next
    24. end sub
    25.  
    26.  
    27. Private sub form_load( yadda yadda)
    28.      
    29.      DA.Fill(DS, "Documents")
    30.      
    31.      buildtable()
    32.  
    33. 'now we just filled the unbound datatable with info from the database,
    34. ' let's fill the listbox
    35.  
    36.     With ListBox1
    37.         .DataSource = dt
    38.         .DisplayMember = "DocumentName"
    39.         .ValueMember = "DocumentOrderId"
    40.         .SelectedIndex = 0
    41.     End With
    42.  
    43. 'now you should be able to move the sort order around since the listbox
    44. 'is actually unbound.  I'm sure you have sort code made already, but
    45. 'now it's just a matter of calling the original document information
    46. 'from the database based on the users selection from the unbound
    47. 'listbox

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    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?
    Tuber

    "I don't know the rules"

  6. #6
    Lively Member RickyH's Avatar
    Join Date
    Oct 2007
    Posts
    92

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    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.
    Tuber

    "I don't know the rules"

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width