473,394 Members | 1,875 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,394 software developers and data experts.

Dropdown in datagrid

I am attempting to put a combo box into a datagrid, I have created
a component class called DataGridComboBoxColumn.cs

*/ I keep getting these 2 errors when I run the project :
1)Object reference not set to an instance of the object AND
2)dgcbcProducts = null*/

The same applies to the other objects daProducts, dsProducts, dgtsProducts,
dgtbcProduts - they are all underlined
in blue saying that they will have a default value of null as they are never
assigned to.
Making them public gets rid of the blue line


This is probably a simple question - but, the answer will stand me in good
stead.

---------------This is the windows form project code
-------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DatagridComboBoxColumn
{

public class frmproducts : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dgproducts;
private System.Windows.Forms.Button btnSubmit;
private System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
public System.Windows.Forms.DataGridTableStyle dgtsproducts;
public System.Windows.Forms.DataGridTextBoxColumn dgtbcProducts;
public System.Windows.Forms.DataGridTableStyle dgtsProducts;
public DataGridComboBoxColumn dgcbcProducts;
public System.Data.SqlClient.SqlDataAdapter daProducts;
public System.Data.DataSet dsProducts;
private System.ComponentModel.Container components = null;

public frmproducts()
{
InitializeComponent();

//Set datagrid preferred height to comboboxheight

dgproducts.PreferredRowHeight = dgcbcProducts.Combobox.Height + 1;
//dgcbcProducts is the problem object

}

Jul 21 '05 #1
1 1537
Hi Chris,

It seems like you have not initialized dgcbcProducts, by which i mean a code
something like
dgcbcProducts = new Combobox() or so should exist.

This is usually added automatically by the WinForms designer in the
InitializeComponent method. Check whether this exists or not.

Maybe you could have changed the name of your combo during design which did
not reflect in the code; or something of that sort could have happened - a
little glitch here or there.

HTH,
Rakesh

"Christopher" wrote:
I am attempting to put a combo box into a datagrid, I have created
a component class called DataGridComboBoxColumn.cs

*/ I keep getting these 2 errors when I run the project :
1)Object reference not set to an instance of the object AND
2)dgcbcProducts = null*/

The same applies to the other objects daProducts, dsProducts, dgtsProducts,
dgtbcProduts - they are all underlined
in blue saying that they will have a default value of null as they are never
assigned to.
Making them public gets rid of the blue line


This is probably a simple question - but, the answer will stand me in good
stead.

---------------This is the windows form project code
-------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DatagridComboBoxColumn
{

public class frmproducts : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dgproducts;
private System.Windows.Forms.Button btnSubmit;
private System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
public System.Windows.Forms.DataGridTableStyle dgtsproducts;
public System.Windows.Forms.DataGridTextBoxColumn dgtbcProducts;
public System.Windows.Forms.DataGridTableStyle dgtsProducts;
public DataGridComboBoxColumn dgcbcProducts;
public System.Data.SqlClient.SqlDataAdapter daProducts;
public System.Data.DataSet dsProducts;
private System.ComponentModel.Container components = null;

public frmproducts()
{
InitializeComponent();

//Set datagrid preferred height to comboboxheight

dgproducts.PreferredRowHeight = dgcbcProducts.Combobox.Height + 1;
//dgcbcProducts is the problem object

}


Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kilic Beg via .NET 247 | last post by:
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime. The dropdown has a different datasource then the...
3
by: Big Dave | last post by:
I know it's been asked a million times before, but I still can't seem to find an answer that works. I've got a dropdown list in the footer template of a datagrid. The dropdown list databinds,...
1
by: Vijay Kerji | last post by:
Hi, I have a datagrid with dropdown list and Remove hyperlink in it as columns. When I remove a row from the datagrid, Dropdown list selection is retaining its previous value. i.e, removed...
6
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: anjupt | last post by:
Hi, I can add values to a dropdown from 1 to 100 using a while loop in page load.ie Dim i = 1 While i <= 100 Me.DropDownList2.Items.Add(i) ' i = i +...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
4
by: youvrajasnsm | last post by:
Hi All, >I am using datagrid control in asp.net with C#. >I have two dropdown list in datagrid e.g. one dropdown have Classname and another have Studentname. >now I want to show all the...
5
by: Me LK | last post by:
I need to add a line to choose a size into a dropdown . Since I have the dropdown nested inside a datagrid this is not working.When a page displays there are several rows of dropdowns but only the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.