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

2 posts, 0 answers
  1. Tan
    Tan avatar
    5 posts
    Member since:
    Mar 2012

    Posted 14 Jun 2012 Link to this post

    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;  
                        }
                    }
                }
     
     
            }
  2. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 19 Jun 2012 Link to this post

    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 >>
Back to Top