CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    18

    Refreshing data of a combobox, what event?

    I have a bound combobox on a windows form, which needs to show the most recent data in the database when the user drops down to select values. I've done this before in a datagridviewcombobox control by using the 'begin edit' and 'end edit' events. The stand alone combobox does not have those events, so which event would be best to use, to seamlessly show the user the most recent data?

    I have tried the 'Enter' event, but if you just click on the combobox, it flashes (not on my machine, but on a slower XP machine). It flashes the values enough to be annoying to the user... I have also tried using the drop down event, but the code I was using was not allowing the drop down event from finishing because I could not get the control to drop down. I also have code in the selectedIndexChanged event, to populate other fields ont he screen based on the user's choice, so the code I need to write needs to refresh the combobox without 'changing the index' to somthing other than 0... To fix this I save the selectedIndex, reload the data, and reset the selected index... which just now I realized that that won't work because the order of the data could change, and the selected index might be different.. I need to base off the value.... Anyhoo, this is what I use now, on the 'Enter' event which causes the control to flash..

    _transactionsIndex = cboTransactions.SelectedIndex;
    transactionTableAdapter.FillBy(_dtTransactions);
    cboTransactions.SelectedIndex = _transactionsIndex;

    So, any ideas on which event I need to use to get the most recent data available to the user, when they click the box? Again, this screen adds items all the time, and other screens might add data to the list...

    Thanks,

    Brandon

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Refreshing data of a combobox, what event?

    I normally do this in the DropDown Event.

    I don't understand what you mean by...

    Quote Originally Posted by bjswifty
    I have also tried using the drop down event, but the code I was using was not allowing the drop down event from finishing because I could not get the control to drop down.
    when putting code into the DropDown Event, the box will not drop down until the code has completed firing. With database access happening during that block, I could see where it may take a few seconds for the box to actually drop down to show the new values.

  3. #3
    Join Date
    May 2008
    Posts
    18

    Re: Refreshing data of a combobox, what event?

    Ok, let me explain my problem with using the drop down event. I took out the code which resets the selected index, and am only left with:

    transactionTableAdapter.FillBy(_dtTransactions);

    What it is doing is selecting the 0 index of the combobox after the table adapter fills the table which is used as the data source, thus not showing the drop down box for users to choose a value. Basically forcing the index 0 to be selected...

    Any ideas on why this is happening?

    Thanks,

    Brandon

  4. #4
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Refreshing data of a combobox, what event?

    I don't normally use adapters for database access. Is selecting the 0 index the default behavior of the adapter?

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

Featured