Results 1 to 2 of 2

Thread: [RESOLVED] Problem with DataTable Updating a Combobox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Resolved [RESOLVED] Problem with DataTable Updating a Combobox

    Hi

    I have a combobox which is used as a filter its updated in real time as the user types and works fine but i had a problem when populating the initial datatable that holds all the items that are filtered into the combobox via a BindingSource.

    What i 'Was' doing was looping through a DataTable and adding rows to the DataTable that was used with the combobox but the AddRow method was simply to slow and took 30-60 seconds just for a few hundred rows...

    So i decided to try and use the .Select method to pull the results instead of looping the original DataTable and dump the results into the DataTable used on the combobox.

    This method seems to be failing for some reason and i can see the results in the DataTable but the BindingSource doesnt reflect the new results and in fact still shows some old results which is strange to me.

    so the Setup is this

    DataTable1 holds the data im collecting for the filter
    DataTable2 holds the collected data
    BindingSource1 is between DataTable2 and the Combobox used to provide realtime filtering

    this all works fine when i use the loop but doesnt when i used the DataTable.Select method...

    Any Ideas?



    Additional Info:

    This is the code im using instead of the loop
    --DT_Feedyard is what holds the data used for the combobox
    --DT is the table i get the data from
    --FiterBinder is the BindingSource

    the objects and controls are already bound just in case your wandering

    Code:
    DT_Feedyard = DT.Select("[Type] IN ('P', 'L', 'M') AND [FYID] IS NOT NULL").CopyToDataTable
    
    'refresh the combobox list
    FilterBinder_Feedyard.ResetBindings(False)
    i checked the tables using the DataTableViewer and all the data is there, but the BindingSource doesnt seem to get the data.
    Last edited by GBeats; Nov 17th, 2017 at 10:55 PM.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: Problem with DataTable Updating a Combobox

    OK i found a pearl in google that just made my brain tick.....

    HERE

    turns out replacing the entire object (Datatable) creates a whole new object and the old one is still in memory? learn something everyday i guess.


    so i made a few changes (note i added some parts i left out earlier to get my desired results

    Code:
    DT.Columns(14).ColumnName = "Text"
            DT.Columns(15).ColumnName = "Value"
    
            Dim View As New DataView
            View = DT.Select("[Type] IN ('P', 'L', 'M') AND [Value] IS NOT NULL", "[Text] ASC").CopyToDataTable.DefaultView
            DT_Feedyard = View.ToTable(True, "Text", "Value")
    
    
            'DT_Feedyard = DT.Select("[Type] IN ('P', 'L', 'M') AND [FYID] IS NOT NULL").CopyToDataTable
    
            FilterBinder_Feedyard.DataSource = DT_Feedyard
    
    
            'refresh the combobox list
            'FilterBinder_Feedyard.ResetBindings(False)
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


Tags for this Thread

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