private void grdBO_CellClick(object sender, DataGridViewCellEventArgs e) { DataGridViewComboBoxCell boSizeRangeCell = new DataGridViewComboBoxCell(); boSizeRangeCell.DataSource = fillGridSizeMasterCol();// DataTable boSizeRangeCell.DisplayMember = "SizeType"; boSizeRangeCell.ValueMember = "SizeKey"; boSizeRangeCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; grdBO.CurrentRow.Cells[ModConstant.cBOSizeRange] = boSizeRangeCell; } private void grdBO_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control is DataGridViewComboBoxEditingControl) { ComboBox combo = e.Control as ComboBox; if (combo != null) { combo.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged); combo.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged); } } private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (this.grdBO.CurrentCell.ColumnIndex == this.grdBO.Columns[ModConstant.cBOSizeRange].Index) { if (((ComboBox)sender).SelectedIndex > -1)//||(((ComboBox)sender).Items.Count > 0 )) { string sizekey = ((ComboBox)sender).SelectedValue.ToString(); if (lSizeRangeAdd.Count > 0) { lSizeRangeAdd.Clear(); } lSizeRangeAdd = SetSizeGridHeadersDB(sizekey); // list fill by datatable return by method SetSizeGridHeadersDB ; lSizeRangeRemove = SetSizeGridHeadersDB(sizekey); // list for removing prev //created col if (lSizeRangeAdd.Count > 0) { foreach (string size in lSizeRangeAdd) { DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); col.HeaderText = size; col.Name = size; grdBO.Columns.Insert(grdBO.Columns[ModConstant.cBOSizeRange].Index + 1, col); grdBO.Columns[grdBO.Columns[ModConstant.cBOSizeRange].Index + 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } } } } } // this method is for getting col header at run time . private List<string> SetSizeGridHeadersDB(String strSizeKey) { strSql = "select * from Sizemaster where sizekey = '" + strSizeKey + "'"; DataSet ds = new DataSet(); List<string> lSizeRange = new List<string>(); Service1 objS = new WebService1.Service1(); try { ds = objS.GetDataSet(strSql, Text); if (ds.Tables[0].Rows.Count > 0) { for (int i = 1 ; i < ds.Tables[0].Columns.Count - 4; i++) { string SizeRange = ds.Tables[0].Rows[0]["size" + i.ToString()].ToString(); if (SizeRange != "") { lSizeRange.Add(SizeRange); } } } } catch (Exception ex) { } finally { objS = null; ds = null; } return lSizeRange; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)