X - prevent selectionindexchange_event trigger when assign datasource?

(Hi,
when I assign .datasouce by mousedown_event, it always sets item (0) from datasouce as the initial default value without blank text (It has the feeling that the user has not chosen but it has chosen before.) . Can I prevent this until the user chooses? because if so then selectedindexchanged will away run 2 times.

3 Replies

DV Duraimurugan Vedagiri Syncfusion Team June 1, 2020 12:04 PM UTC

Hi GridLock,

You can achieve this by assigning the MultiColumnComboBox.SelectedIndex value as -1 and MultiColumnComboBox.Text as empty. Please refer the below code snippet for your reference.

Code Snippet
private void MultiColumnComboBox1_MouseDown(object sender, MouseEventArgs e) 
{ 
    if (this.multiColumnComboBox1.DataSource == null) 
    { 
        //Create dataTable 
        DataTable dt = new DataTable("Table1"); 
        dt.Columns.Add("FirstName"); 
        dt.Columns.Add("LastName"); 
 
        // Create a Data Set 
        DataSet ds = new DataSet(); 
        ds.Tables.Add(dt); 
        dt.Rows.Add(new string[] { "John", "Tina" }); 
        dt.Rows.Add(new string[] { "Mary", "Anu" }); 
        DataView view = new DataView(dt); 
 
        // DATASOURCE is DATAVIEW 
        this.multiColumnComboBox1.DataSource = view; 
        this.multiColumnComboBox1.DisplayMember = "FirstName"; 
        this.multiColumnComboBox1.ValueMember = "LastName"; 
        this.multiColumnComboBox1.SelectedIndex = -1; 
        this.multiColumnComboBox1.Text = string.Empty; 
    } 
} 

Regards,
Durai


TG The GridLock June 1, 2020 04:48 PM UTC

It still looks quite clear Durai , I tried changing the fontcolor to white earlier to obscure it but it didn't work. I will live with it temporarily!


DV Duraimurugan Vedagiri Syncfusion Team June 2, 2020 07:56 AM UTC

Hi GridLock,

Thanks for your update.

The MultiColumnComboBox default SelectedIndex is zero, so the first item is selected while assign the datasource. Also, you can prevent this with help of given snippet in the previous update.

Please let us know if you need any further assistance.

Regards,
Durai

Loader.
Up arrow icon