Dropdown in datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
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

}
 
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
 
Back
Top