hi,
i am facing problem with attaching combobox to a cell of a datagrid. namely
to the cell 3rd row 4 column..
then the combobox should display the content of that particular cell...
can anyone help me in this regard
Thanks
Geeta
Bajoo - 28 Oct 2005 13:43 GMT
Dear Geeta,
what I have understood from ur question, the
following code might help you in ur task. It binds a ArrayList to a
combobox and then attaches the comboBox to the DataGrid
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "ArrayList";
int colwidth = (this.dataGrid1.ClientSize.Width
- ts.RowHeaderWidth
- SystemInformation.VerticalScrollBarWidth - 2) / 2;
// Create a column for the "Name" property
// defined in the EntityField Class
DataGridTextBoxColumn cs = new DataGridTextBoxColumn();
cs.MappingName = "FieldName"; // Public property name
cs.HeaderText = "Field Name";
cs.Format = "f4";
cs.Width = colwidth;
cs.ReadOnly=true;
ts.GridColumnStyles.Add(cs);
cs = new DataGridTextBoxColumn();
cs.MappingName = "Order"; // Public property name
cs.HeaderText = "Order";
cs.Format = "f4";
cs.Width = colwidth;
cs.ReadOnly=true;
ts.GridColumnStyles.Add(cs);
// Add the custom tablestyle to the DataGrid
this.dataGrid1.TableStyles.Clear();
this.dataGrid1.TableStyles.Add(ts);
this.dataGrid1.DataSource =lstOrderByFields;
DataGridTextBoxColumn datagridtextBox=
(DataGridTextBoxColumn)this.dataGrid1.TableStyles[0].GridColumnStyles[1];
//for(int j=0;j<lstTables.Count;j++)
cmb=new ComboBox();
cmb.Height=datagridtextBox.TextBox.Height;
cmb.Width=colwidth;
cmb.DropDownStyle=ComboBoxStyle.DropDownList;
cmb.Items.Add(ASCENDING);
cmb.Items.Add(DESCENDING);
cmb.Dock=DockStyle.Fill;
cmb.SelectedIndexChanged+=new
EventHandler(cmb_SelectedIndexChanged);
datagridtextBox.TextBox.Controls.Add(cmb);
I hope it helps.
Regards,
Naveed Ahmad Bajwa
Kalsoft Pvt Ltd