This is a migrated thread and some comments may be shown as answers.

How can I input data into 2 gridviewmulticolumncomboboxes(2 columns)

1 Answer 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tan
Top achievements
Rank 1
Tan asked on 15 Jun 2012, 04:23 AM
I use this code but I dont' work. Please help me.
// Add data into gridview multicolumnbobox

bool isColumnAdded = false;
bool isColumnAdded1 = false;
void radGridViewDetail_CellBeginEdit(object sender, EventArgs e)
        {
            GridViewEditManager edit = (GridViewEditManager)sender;
             
            GridViewColumn data = edit.GridViewElement.CurrentColumn;
            //MessageBox.Show(data.Index.ToString());
            if (data.Index == 1)
            {
                if (this.radGridViewDetail.CurrentColumn is GridViewMultiComboBoxColumn && data.Index == 1)
                {
                    if (isColumnAdded == false)
                    {
                        isColumnAdded = true;
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridViewDetail.ActiveEditor;
                        editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
                        editor.EditorControl.Columns.Clear();
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("strProductID"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("memDescription"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("dblUnitsInStock"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("dblUnitsAllocated"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("curSalesPrice"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("strWarehouseID"));
                        editor.EditorControl.Columns[0].HeaderText = "Item No";
                        editor.EditorControl.Columns[1].HeaderText = "Description";
                        editor.EditorControl.Columns[2].HeaderText = "Stock";
                        editor.EditorControl.Columns[3].HeaderText = "Available";
                        editor.EditorControl.Columns[4].HeaderText = "Price";
                        editor.EditorControl.Columns[5].HeaderText = "Warehouse";
                        editor.AutoSizeDropDownToBestFit = true;
                        //if (editor.EditorControl.Columns.Count == 8)
                        //{
                        //    editor.EditorControl.Columns.RemoveAt(7);
                        //    editor.EditorControl.Columns.Remove("strNotes");
                        //}
                    }
                }
            }
            if (data.Index == 2)
            {
                if (this.radGridViewDetail.CurrentColumn is GridViewMultiComboBoxColumn &&  data.Index == 2)
                {
                    if (isColumnAdded1 == false)
                    {
                        isColumnAdded1 = true;
                        RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridViewDetail.ActiveEditor;
                        editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
                        editor.EditorControl.Columns.Clear();
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("strWarehouseID"));
                        editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("strNotes"));
                        editor.EditorControl.Columns[0].HeaderText = "Warehouse ID";
                        editor.EditorControl.Columns[1].HeaderText = "Notes";
                        editor.AutoSizeDropDownToBestFit = true;  
                    }
                }
            }
 
 
        }

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 Jun 2012, 08:11 AM
Hi Tan,

Thank you for writing.

I guess by "I don't work" you mean that the columns are added but are not always displayed in the correct column. If so, this is caused by the fact that the editors in RadGridView are being reused. For this reason, the CellBeginEdit  event is not convenient for this scenario. You can safely use the CellEditorInitialized to add the desired customization.

I hope this helps. Let us know if we can be of further assistance.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Tan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or