473,287 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

ComboBox in DataGrid - Stuck! Help with Debugging!!

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
1 2459
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Samuel Hon | last post by:
Hi I'm a bit stuck with a SELECT query. This is a simplified version of what I need. I've had a look in a few books and online but I'm definitely missing something. I'm trying to avoid looping...
1
by: Optimus | last post by:
When I got vs.net 2005 Beta 2 installed in my PC, It was getting trouble with debugging in 2003. When I pressed F5 it said "Unable to start debugging on the web server. Could not start ASP.NET...
3
by: dmalhotr2001 | last post by:
Hi, I have a datagrid hypothetically with this data: id | text | link ------------------------------- 1 | first row | delete button 2 | second row | delete button ...
2
by: John Dalberg | last post by:
I hsve an ASP.NET app whch hangs when I start it with debugging and the CPU usage is 100%. Starting without debugging works fine. Any ideas? -- John Dalberg
1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
9
by: lostnewmexico | last post by:
This one has me at whit's end. In order for this to make sense, I will have to lay out the "facts" to get a hypothesis. There is no easy way to explain this. Environment: VC2005. MFC...
1
by: t.kleczek | last post by:
Hi. I have a problem with debugging in Dev C++ 4.9.9.2 Whenever I try to debug the console c++ program the following message pops up: "Your project does not have debbuging information, do you...
2
by: kulet | last post by:
"2nd post as i noone could do it" Hi guys! Got stuck with this.. I have a chunks of text separated with blanc line. All I need is to take every last 3 lines of that text before the blanc line...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.