G
Guest
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
}
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
}