Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am looking for a way to feed the combobox cell of a datagridview during the initialization of the datasource binding operation.

I was hoping to apply the cmb.Items.Add(...) operation there but RowsAdded does not come for each new row, it is a bit random.

If I apply that operation after the binding is completed, it takes a very long time to update the combobox item for in my case 1024 rows.

Does somebody know a way to feed the combobox on demand if I do not use the virtualmode system but the datasource binding way ?

What I have tried:

I tried:
C#
RowsAdded += AdvancedDataGridView_RowsAdded;

private void AdvancedDataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            if (_onRowAdded != null)
            {

                foreach (System.Windows.Forms.DataGridViewRow row in base.Rows)
                {
                    T values = (T)row.DataBoundItem;
                    values = Copy(values);
                    _onRowAdded(row, values);
                }
            }
        }

        private void OnRowAdded(DataGridViewRow row, Channel values)
        {
            mpUserControls.DataGridViewColumn col = _grid.Columns["InputMode"];

            System.Windows.Forms.DataGridViewCell cell = row.Cells[col.Index];

            if (cell is DataGridViewComboBoxCell)
            {
                DataGridViewComboBoxCell combo = (DataGridViewComboBoxCell)cell;
                combo.Value = string.Empty;
                combo.Items.Clear();
                if (combo.Items.Count <= 0)
                {
combo.Items.Add(Channel.netInputMode.INPUTMODE_VOLTAGE.ToString());
                    if (row.Index % 2 != 0)
combo.Items.Add(Channel.netInputMode.INPUTMODE_ICP.ToString());
                }

                combo.Value = values.InputMode;
            }
        }


This works fine for rows index 0 and 1 but not until the 1024 row count.

Do you know if there is a possible way to complete that expectation ?

Thank you so much in advance.
Best regards.
Miqi
Posted
Comments
RickZeeland 16-Jun-17 13:52pm    
I think you should reset the BindingSource, e.g. set the .DataSource to NULL and then rebind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900