We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to Set MultiColumnComboBox to Empty Selection?

I''d like to set the selected value of a MultiColumnComboBox to empty (blank) value. I have tried the following, but the first item in the list is selected rather than blank: this.MultiColumnComboBox.SelectedIndex = -1; this.MultiColumnComboBox.SelectedItem = null; this.MultiColumnComboBox.UpdateText(true); I''ve set the DisplayMember, ValueMember and DataSource properties from a filled DataTable. Using 3.0.1.0 but had the same prob under previous version also. Thanks, --Van Baker

8 Replies

AD Administrator Syncfusion Team December 24, 2004 12:31 AM UTC

Where are you trying to do this? If I add a buttom handler to the sample we ship in 3.0.1.0, and use this code, then either line below works to display an empty cell in the sample. private void button1_Click(object sender, System.EventArgs e) { //this.multiColumnBoundCombo.SelectedValue = DBNull.Value; this.multiColumnBoundCombo.SelectedIndex = -1; } Does the column in your DataTable allow nulls? If not, then trying to set a null there would throw an exception which would interfere with the normal behavior. If you are trying to do it on the initial display, then you have to delay setting it until the combobox is about to be drawn. Otherwise, your setting will be stepped on. One way you can do this is to subscribe to the commbobx paint event. In the handler, unsubscribe (so the code is only hit once) and set the value there. private void multiColumnBoundCombo_Paint(object sender, PaintEventArgs e) { this.multiColumnBoundCombo.Paint += new PaintEventHandler(multiColumnBoundCombo_Paint); this.multiColumnBoundCombo.SelectedIndex = -1; }


VB vbaker December 24, 2004 12:52 PM UTC

I can get the initial display to work using your paint handler, and setting SelectedIndex to -1 does, indeed, blank out the combobox. However, I have several of these MultiColumnComboBoxes on a tab page of a tabControlAdv, each with its own datasource, and bound to different columns in the data table. If I select a different tab page and then come back to the page with the combos, the nulled out combos revert back to display the first item in the list rather than blank. The comboboxes with non-null values retain their proper values after the page switch. --Van Baker


AD Administrator Syncfusion Team December 24, 2004 02:31 PM UTC

In the paint code above that line should have been this.multiColumnBoundCombo.Paint -= new PaintEventHandler(multiColumnBoundCombo_Paint); If you are using TabPages, then when you leave the tab, you can resubscribe to the grid''s Paint event so the next time it appears, it should set the SelectedIndex to -1.


VB vbaker December 24, 2004 03:50 PM UTC

>In the paint code above that line should have been > >this.multiColumnBoundCombo.Paint -= new PaintEventHandler(multiColumnBoundCombo_Paint); > Yeah, I caught that typo. >If you are using TabPages, then when you leave the tab, you can resubscribe to the grid''s Paint event so the next time it appears, it should set the SelectedIndex to -1. The trouble is, if the user has actually selected an item from the pulldown, or the bound value was non-null, I would not want to reset the control back to null. Something internal appears to be changing the index from -1 to zero when the tab pages are changed. Is this a bug, or am I mis-using the control? BTW, Merry Christmas! --Van Baker


AD Administrator Syncfusion Team December 24, 2004 04:59 PM UTC

I do not know whether this is a bug or if it is by design. There is special code in the SelectedIndex setter that sets the value to the CurrencyManager.Position when a -1 is passed in. I have forwarded this thread to the tools team which handles this control to find out how they think this should work.


AD Administrator Syncfusion Team December 26, 2004 08:50 PM UTC

My guess is that it''s not supposed to work this way. After Googling, I''ve found posts to the dotnet groups from people who have encountered similar problems-- with the stock dotnet controls. Microsoft has even published an admission of a CLR bug in the following article: http://support.microsoft.com/default.aspx?scid=KB;EN-US;327244 As for the tab control issue I observed, this, too, has been reported in several posts by people using the stock (Miscrosoft) combo box and tab controls: Changing tab pages actually sets the SelecetedIndex value to 0 if it previously was -1. Perhaps, Syncfusion has inherited this bug (or, if you will, "behavior") from the Framework''s CLR. I have a hack for a work-around: In the tab control''s SelectedIndexChanged event handler set the Tag property of each combo box to the current SelectedIndex value when leaving the page where the combos are located. Then, when returning back to that tab page, set the SelectedIndex to the Tag property. This requires handling both the SelectedIndexChanging (when saving to the Tag) and SelectedIndexChanged (when restoring from the Tag) events.)


AD Administrator Syncfusion Team December 26, 2004 09:07 PM UTC

Oops.. Somehow I accidentally posted my reply before I was quite done typing the final paragraph. The previous post should have read... My guess is that it''s not supposed to work this way. After Googling, I''ve found posts to the dotnet groups from people who have encountered similar problems-- with the stock dotnet controls. Microsoft has even published an admission of a CLR bug in the following article: http://support.microsoft.com/default.aspx?scid=KB;EN-US;327244 As for the tab control issue I observed, this, too, has been reported in several posts by people using the stock (Miscrosoft) combo box and tab controls: Changing tab pages actually sets the SelecetedIndex value to 0 if it previously was -1. Perhaps, Syncfusion has inherited this bug (or, if you will, "behavior") from the Framework''s CLR. I have discovered a hack for a work-around: In the tab control''s SelectedIndexChanging event handler set the Tag property of each combo box equal to the current SelectedIndex value when leaving the page where the combos are located. Then, when returning back to that tab page, set the SelectedIndex property equal to the Tag property. This requires handling both the SelectedIndexChanging (when saving to the Tag) and SelectedIndexChanged (when restoring from the Tag) events. Not too very pretty code, but it works. Sorry if this thread belonged in the Tools forum, but I couldn''t figure out exactly where it belonged. Regards, --Van Baker


AD Administrator Syncfusion Team December 29, 2004 11:21 AM UTC

Hi Van, Thanks for sharing this information with us and also for the workaround. We appreciate your continued interest in Syncfusion products. Regards, Guru Patwal Syncfusion, Inc.

Loader.
Live Chat Icon For mobile
Up arrow icon