Hello , i want to see if GridViewMultiComboBox is suitable for our application and i want the end user to type any text gridview multicombo box column and i checked https://www.telerik.com/forums/editable-values-for-new-row-using-gridviewmulticomboboxcolumn but it is giving me problem after end user type and add new item to dropdown list editor , when i go to different row and try to change selected value og MultiComboBox , it doesnt fire selectedvalue changed ..
Also when you change the selected value of GridviewMultiComboBox column it should automatically get the price of the item , update gridview item price column , and multiply with quantity column and update total column ,,,it does that but after i added new item manually , it doesnt do that ..Code is below ..If you see the pictures , after added dropdown list item , changing the item from the list doesnt effect the price and item number and total column anymore
private void ERPDataForm_Load(object sender, EventArgs e)
{
this.radGridView1.MasterTemplate.AutoGenerateColumns = false;
this.radGridView1.EnableFiltering = false;
this.radGridView1.MasterTemplate.ShowHeaderCellButtons = false;
this.radGridView1.MasterTemplate.ShowFilteringRow = false;
this.radGridView1.MasterTemplate.EnableGrouping = false;
this.radGridView1.MasterTemplate.AllowAddNewRow = true;
this.radGridView1.AddNewRowPosition = SystemRowPosition.Bottom;
this.radGridView1.AllowAutoSizeColumns = true;
this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewDecimalColumn qtyColumn = new GridViewDecimalColumn();
qtyColumn.Name = "QtyColumn";
qtyColumn.HeaderText = "Qty";
qtyColumn.FieldName = "Quantity";
qtyColumn.DecimalPlaces = 0;
qtyColumn.TextAlignment = ContentAlignment.MiddleCenter;
qtyColumn.Width = 80;
radGridView1.MasterTemplate.Columns.Add(qtyColumn);
GridViewDecimalColumn itemIDColumn = new GridViewDecimalColumn();
itemIDColumn.Name = "itemIDColumn";
itemIDColumn.HeaderText = "Item ID";
itemIDColumn.FieldName = "ItemID";
itemIDColumn.DecimalPlaces = 0;
itemIDColumn.TextAlignment = ContentAlignment.MiddleCenter;
itemIDColumn.Width = 100;
radGridView1.MasterTemplate.Columns.Add(itemIDColumn);
DataTable gg = new DataTable();
gg = CreateDataTable2();
GridViewMultiComboBoxColumn descriptionColumn = new GridViewMultiComboBoxColumn();
descriptionColumn.DataSource = gg;
descriptionColumn.Name = "DecriptionColumn";
descriptionColumn.HeaderText = "Description";
descriptionColumn.DisplayMember = "DescX";
descriptionColumn.FieldName = "ItemID";
descriptionColumn.ValueMember = "ItemIDX";
descriptionColumn.DropDownStyle = RadDropDownStyle.DropDown;
descriptionColumn.AutoCompleteMode = AutoCompleteMode.Suggest;
descriptionColumn.Width = 500;
descriptionColumn.AutoSizeMode = BestFitColumnMode.AllCells;
radGridView1.MasterTemplate.Columns.Add(descriptionColumn);
GridViewDecimalColumn itemPriceColumn = new GridViewDecimalColumn();
itemPriceColumn.Name = "itemPriceColumn";
itemPriceColumn.HeaderText = "Unit Price";
itemPriceColumn.FieldName = "ItemPrice";
itemPriceColumn.DecimalPlaces = 2;
itemPriceColumn.TextAlignment = ContentAlignment.MiddleRight;
itemPriceColumn.Width = 120;
itemPriceColumn.FormatString = "${0:###,###0.00}";
radGridView1.MasterTemplate.Columns.Add(itemPriceColumn);
GridViewDecimalColumn itemTotalColumn = new GridViewDecimalColumn("Total Amount");
itemTotalColumn.Name = "itemTotalColumn";
itemTotalColumn.HeaderText = "TOTAL";
itemTotalColumn.FieldName = "ItemTotal";
itemTotalColumn.Width = 110;
itemTotalColumn.Expression = "itemPriceColumn * QtyColumn";
itemTotalColumn.FormatString = "${0:###,###0.00}";
radGridView1.MasterTemplate.Columns.Add(itemTotalColumn);
BusinessLayerInvoiceItems BLII = new BusinessLayerInvoiceItems();
ArrayList al = new ArrayList();
al = BLII.GetInvoiceItemsbyInvoiceID(INVOICEID);
this.radGridView1.DataSource = al;
this.radGridView1.CellEditorInitialized += new GridViewCellEventHandler(radGridView1_CellEditorInitialized);
this.radGridView1.EditorRequired += new EditorRequiredEventHandler(radGridView1_EditorRequired);
this.radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
}
private DataTable CreateDataTable2()
{
DataTable dtable2 = new DataTable();
//set columns names
dtable2.Columns.Add("ItemIDX", typeof(System.Int32));
dtable2.Columns.Add("Descx", typeof(System.String));
dtable2.Columns.Add("ItemPrice", typeof(System.String));
dtable2.Columns.Add("ItemQuantity", typeof(System.String));
BusinessLayerItem BLC = new BusinessLayerItem();
ArrayList al = new ArrayList();
Item c = new Item();
al = BLC.GetItems();
DataRow drowX = dtable2.NewRow();
drowX["ItemIDX"] = -1;
drowX["DescX"] = "";
drowX["ItemPrice"] = "";
drowX["ItemQuantity"] = "";
dtable2.Rows.Add(drowX);
for (int i = 0; i < al.Count; i++)
{
//Add Rows
DataRow drow = dtable2.NewRow();
drow["ItemIDX"] = ((Item)al[i]).ItemId;
drow["DescX"] = ((Item)al[i]).ItemName.ToUpper();
drow["ItemPrice"] = ((Item)al[i]).ItemPrice;
drow["ItemQuantity"] = ((Item)al[i]).ItemQuantity;
dtable2.Rows.Add(drow);
}
return dtable2;
}
protected void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
if (e.EditorType == typeof(RadMultiColumnComboBoxElement) )
{
if (!isrowadded)
{
e.EditorType = typeof(CustomRadMultiColumnComboBoxElement);
isrowadded = false;
}
else
{
e.EditorType = typeof(RadMultiColumnComboBoxElement);
}
}
}
protected void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadMultiColumnComboBoxElement mccbEditor = e.ActiveEditor as RadMultiColumnComboBoxElement;
if (mccbEditor != null)
{
FilterDescriptor descriptor = new FilterDescriptor("DescX", FilterOperator.StartsWith, null);
mccbEditor.EditorControl.FilterDescriptors.Add(descriptor);
mccbEditor.AutoSizeDropDownToBestFit = true;
}
}
bool isColumnAdded;
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
if (this.radGridView1.CurrentColumn is GridViewMultiComboBoxColumn)
{
if (!isColumnAdded)
{
isColumnAdded = true;
RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridView1.ActiveEditor;
editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("ItemIDX"));
editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("DescX"));
editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("ItemPrice"));
editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("ItemQuantity"));
editor.AutoSizeDropDownToBestFit = true;
editor.SelectedIndexChanged += new EventHandler(ProcCode_multiColumnComboElement_SelectedIndexChanged);
}
}
}
void ProcCode_multiColumnComboElement_SelectedIndexChanged(object sender, EventArgs e)
{
if (radGridView1.ActiveEditor is RadMultiColumnComboBoxElement)
{
RadMultiColumnComboBoxElement multiColumnComboElement = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
GridViewRowInfo row = multiColumnComboElement.EditorControl.CurrentRow;
if (row != null)
{
radGridView1.CurrentRow.Cells[1].Value = row.Cells[0].Value;
radGridView1.CurrentRow.Cells[3].Value = row.Cells[2].Value;
}
}
}
bool isrowadded = false;
}
Custom CLASS Below
public class CustomRadMultiColumnComboBoxElement : RadMultiColumnComboBoxElement
{
public CustomRadMultiColumnComboBoxElement()
{
this.AutoFilter = true;
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(RadMultiColumnComboBoxElement);
}
}
public override void ProcessReturnKey(System.Windows.Forms.KeyEventArgs e)
{
try
{
string text = this.Text;
if (!string.IsNullOrEmpty(text))
{
GridViewRowInfo newCurrentRow = this.FindItemExact(text) as GridViewRowInfo;
if (newCurrentRow == null)
{
this.AddTextAsRow(text);
}
}
base.ProcessReturnKey(e);
}
catch (Exception ex)
{
base.ProcessReturnKey(e);
}
}
public override object Value
{
get
{
this.AddTextAsRow(this.Text);
return base.Value;
}
set
{
base.Value = value;
}
}
private int id = 0;
private void AddTextAsRow(string text)
{
for (int i = 0; i < this.EditorControl.Rows.Count; i++)
{
GridViewRowInfo newCurrentRow = this.EditorControl.Rows[i] as GridViewRowInfo;
string trr = newCurrentRow.Cells[1].Value.ToString();
if (trr == Text.Trim() || Text.Trim()=="")
{
return;
}
}
GridViewDataRowInfo row = (GridViewDataRowInfo)this.EditorControl.Rows.AddNew();
row.Cells["ItemIDX"].Value = id;
row.Cells["DescX"].Value = text;
row.Cells["ItemPrice"].Value = id;
row.Cells["ItemQuantity"].Value = id;
// this.EditorControl.Rows.Add(id, text);
id++;
}
}