|
-
October 10th, 2008, 03:26 PM
#1
ComboBox event issue
Hi guys,
I have a ComboBox which when entering focus I wish for it to populate itself with values from an SQL server.
At the moment I have:
Code:
private void supplierNameBox_Enter(object sender, EventArgs e)
{
SupplierName.Clear(); //This is a table
DbDataAdapter.SelectCommand = supplierNameSelectCommand;
DbDataAdapter.Fill(DbMenuDataSet, "Supplier");
}
However when my first click that brings the box into focus is the drop-down arrow, it somehow manages to duplicate the data entries, displaying them twice. Yet when i add a line such as:
Code:
MessageBox.Show("bla");
to the top of the function it works fine, except obviously I don't want a message box popping up!
Any help would be amazing guys.
-
October 11th, 2008, 04:23 AM
#2
Re: ComboBox event issue
Firstly, check that the entries haven't been added in the IntializeComponent method of the form.
This can happen if you add entries to combo boxes/list boxes etc in the constructor of the form : when in the designer the constructor gets called and when you then save it also saves the contents of the combo boxes.
Are you sure you don't have duplicated entries in the database ? Or maybe your SQL statement for filling the combo box is returning duplicated results : a 'SELECT DISTINCT' should sort this out.
Maybe you need to call Items.Clear() on the combo box before filling it too.
Darwen.
Last edited by darwen; October 11th, 2008 at 04:26 AM.
-
October 11th, 2008, 08:55 AM
#3
Re: ComboBox event issue
I think my issue is that the clear() command is asynchronous. So I need some kind of flag however the Clearing and Cleared events don't seem to work properly.
-
October 11th, 2008, 09:53 AM
#4
Re: ComboBox event issue
put this line of code at the beginning of the Enter event.
Code:
supplierNameBox.Items.Clear();
-
October 11th, 2008, 10:42 AM
#5
Re: ComboBox event issue
I've tried that and it prevents the box from displaying anything at all.
From what I can now see the table is populating with 4 values even though there are definitely only two entries on the database.
If I stop clearing the table and set constraints on the primary key, only the two values will show, but I cant enter the drop down box until I have clicked elsewhere on the ComboBox first.
I still need clear in order to refresh my data. However, when using clear() with the restraints, it completely ignores them and loads double values again. What's strange is when clicking on the ComboBox and running clear() once, it removes the two rows correctly. However entering the ComboBox by clicking immediately on the dropdown arrow forces the Enter event to run twice, the second time around clear doesn't seem to work at all and 4 values are loaded into the table.
EDIT: Ok I've realised the Fill() command does what Clear() does anyway. This fixes my duplicate issue. However the problem is that when I fill the box with new data it prevents the use of the drop down arrow until the cursor is active in the box first.
Last edited by Scribe; October 11th, 2008 at 10:56 AM.
-
October 11th, 2008, 03:29 PM
#6
Re: ComboBox event issue
why don't you populate the box in the "DropDown" event?
-
October 12th, 2008, 02:58 PM
#7
Re: ComboBox event issue
 Originally Posted by eclipsed4utoo
why don't you populate the box in the "DropDown" event?
The issue is that I also employ auto-complete, so users may not drop-down at all. Also having both Enter and DropDown events doesn't solve the issue. When clicking on the dropdown box before entering the box will populate then lock out the DropDown arrow and related events until you enter the box by clicking on the text field.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|