ComboBox in DataGrid - Stuck! Help with Debugging!!

A

anonymous

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/issues/03/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!!
 
D

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: (e-mail address removed)
Your acceptance of the license agreement will be required.

Ori
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top