By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,327 Members | 2,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,327 IT Pros & Developers. It's quick & easy.

ComboBox in DataGrid - Stuck! Help with Debugging!!

P: n/a
I've been trying to put a them, please help me out.

Here's the major parts of my code:
public Form1()
{
DataSet myDataSet = new DataSet("myDataSet");
DataTable testTable = new DataTable("table");
testTable.Columns.Add("Col1", typeof(Int32));
testTable.Columns.Add("Col2", typeof(String));
testTable.Rows.Add(testTable.NewRow());
myDataSet.Tables.Add(testTable);
dataGrid1.SetDataBinding(myDataSet, "table");
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "table";
DataGridColumnStyle boolCol = new DataGridBoolColumn();
boolCol.MappingName = "Col1";
boolCol.HeaderText = "ID #";
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
/************************************************** ***************************/
/********PROBLEM MIGHT BE IN AREA BETWEEN THESE
LINES*************************/
/************************************************** ****************************/
// Add a second column style.
DataGridComboBoxColumn comboCol = new DataGridComboBoxColumn();
comboCol.Format = "";
comboCol.FormatInfo = null;
comboCol.HeaderText = "ComboBox Field";
comboCol.MappingName = "Col2";
comboCol.Width = 125;
Rectangle rect = dataGrid1.GetCurrentCellBounds();
comboCol.ComboBox.Location = rect.Location;
comboCol.ComboBox.Show();
ArrayList ar1 = new ArrayList();
ar1.Add(new ComboBoxData("Apple"));
ar1.Add(new ComboBoxData("Banana"));
ar1.Add(new ComboBoxData("Carrot"));
comboCol.ComboBox.DataSource = ar1;
comboCol.ComboBox.DisplayMember = "Value";
comboCol.ComboBox.ValueMember = "Value";
/************************************************** ***************************/
/********PROBLEM MIGHT BE IN AREA BETWEEN THESE
LINES*************************/
/************************************************** ****************************/
ts1.GridColumnStyles.Add(comboCol);
dataGrid1.TableStyles.Add(ts1);
// Set task datagrid preferred height to combo box height
dataGrid1.PreferredRowHeight = comboCol.ComboBox.Height + 1;
}
public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
private ComboBox comboBox;
public DataGridComboBoxColumn()
{
// Create combobox and force DropDownList style
this.comboBox = new ComboBox();
this.comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBox.BringToFront();
this.comboBox.Leave += new EventHandler(comboBox_Leave);
}
public ComboBox ComboBox
{get { return comboBox; }}
}

I basically got the DataGridComboBoxColumn class code from:
http://msdn.microsoft.com/msdnmag/is.../08/DataGrids/, and I only
listed some parts of it here. My problem is creating the 2nd column
which should have a ComboBox style. I think my data binding works,
but for some reason the ComboBox won't show up in the grid.

Thanks in Advance!!
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DNE
Can't help you with the DataGridComboBoxColumn however I can suggest a
simpler alternative.

Fully documented. Requires .NET framework 1.1 or later.

You will be allowed to use the libraries in any application - private or
commercial, and distribute them as part of your application, royalty-free.

E-mail me for your free copy: or*@s-e-a.com.au
Your acceptance of the license agreement will be required.

Ori
"anonymous" <si*******@hotmail.com> wrote in message
news:41*************************@posting.google.co m...
I've been trying to put a them, please help me out.

Here's the major parts of my code:
public Form1()
{
DataSet myDataSet = new DataSet("myDataSet");
DataTable testTable = new DataTable("table");
testTable.Columns.Add("Col1", typeof(Int32));
testTable.Columns.Add("Col2", typeof(String));
testTable.Rows.Add(testTable.NewRow());
myDataSet.Tables.Add(testTable);
dataGrid1.SetDataBinding(myDataSet, "table");
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "table";
DataGridColumnStyle boolCol = new DataGridBoolColumn();
boolCol.MappingName = "Col1";
boolCol.HeaderText = "ID #";
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
/************************************************** *************************
**/ /********PROBLEM MIGHT BE IN AREA BETWEEN THESE
LINES*************************/
/************************************************** *************************
***/ // Add a second column style.
DataGridComboBoxColumn comboCol = new DataGridComboBoxColumn();
comboCol.Format = "";
comboCol.FormatInfo = null;
comboCol.HeaderText = "ComboBox Field";
comboCol.MappingName = "Col2";
comboCol.Width = 125;
Rectangle rect = dataGrid1.GetCurrentCellBounds();
comboCol.ComboBox.Location = rect.Location;
comboCol.ComboBox.Show();
ArrayList ar1 = new ArrayList();
ar1.Add(new ComboBoxData("Apple"));
ar1.Add(new ComboBoxData("Banana"));
ar1.Add(new ComboBoxData("Carrot"));
comboCol.ComboBox.DataSource = ar1;
comboCol.ComboBox.DisplayMember = "Value";
comboCol.ComboBox.ValueMember = "Value";
/************************************************** *************************
**/ /********PROBLEM MIGHT BE IN AREA BETWEEN THESE
LINES*************************/
/************************************************** *************************
***/ ts1.GridColumnStyles.Add(comboCol);
dataGrid1.TableStyles.Add(ts1);
// Set task datagrid preferred height to combo box height
dataGrid1.PreferredRowHeight = comboCol.ComboBox.Height + 1;
}
public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
private ComboBox comboBox;
public DataGridComboBoxColumn()
{
// Create combobox and force DropDownList style
this.comboBox = new ComboBox();
this.comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBox.BringToFront();
this.comboBox.Leave += new EventHandler(comboBox_Leave);
}
public ComboBox ComboBox
{get { return comboBox; }}
}

I basically got the DataGridComboBoxColumn class code from:
http://msdn.microsoft.com/msdnmag/is.../08/DataGrids/, and I only
listed some parts of it here. My problem is creating the 2nd column
which should have a ComboBox style. I think my data binding works,
but for some reason the ComboBox won't show up in the grid.

Thanks in Advance!!

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.