Dropdown in datagrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher

    #1

    Dropdown in datagrid

    I am attempting to put a combo box into a datagrid, I have created
    a component class called DataGridComboBo xColumn.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.Collecti ons;
    using System.Componen tModel;
    using System.Windows. Forms;
    using System.Data;


    namespace DatagridComboBo xColumn
    {

    public class frmproducts : System.Windows. Forms.Form
    {
    private System.Windows. Forms.DataGrid dgproducts;
    private System.Windows. Forms.Button btnSubmit;
    private System.Data.Sql Client.SqlComma nd
    sqlSelectComman d1;
    private System.Data.Sql Client.SqlComma nd sqlInsertComman d1;
    private System.Data.Sql Client.SqlComma nd sqlUpdateComman d1;
    private System.Data.Sql Client.SqlComma nd sqlDeleteComman d1;
    private System.Data.Sql Client.SqlDataA dapter sqlDataAdapter1 ;
    public System.Windows. Forms.DataGridT ableStyle dgtsproducts;
    public System.Windows. Forms.DataGridT extBoxColumn dgtbcProducts;
    public System.Windows. Forms.DataGridT ableStyle dgtsProducts;
    public DataGridComboBo xColumn dgcbcProducts;
    public System.Data.Sql Client.SqlDataA dapter daProducts;
    public System.Data.Dat aSet dsProducts;


    private System.Componen tModel.Containe r components = null;

    public frmproducts()
    {
    InitializeCompo nent();

    //Set datagrid preferred height to comboboxheight

    dgproducts.Pref erredRowHeight = dgcbcProducts.C ombobox.Height + 1;
    //dgcbcProducts is the problem object

    }





  • Rakesh Rajan

    #2
    RE: Dropdown in datagrid

    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
    InitializeCompo nent 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

    "Christophe r" wrote:
    [color=blue]
    > I am attempting to put a combo box into a datagrid, I have created
    > a component class called DataGridComboBo xColumn.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.Collecti ons;
    > using System.Componen tModel;
    > using System.Windows. Forms;
    > using System.Data;
    >
    >
    > namespace DatagridComboBo xColumn
    > {
    >
    > public class frmproducts : System.Windows. Forms.Form
    > {
    > private System.Windows. Forms.DataGrid dgproducts;
    > private System.Windows. Forms.Button btnSubmit;
    > private System.Data.Sql Client.SqlComma nd
    > sqlSelectComman d1;
    > private System.Data.Sql Client.SqlComma nd sqlInsertComman d1;
    > private System.Data.Sql Client.SqlComma nd sqlUpdateComman d1;
    > private System.Data.Sql Client.SqlComma nd sqlDeleteComman d1;
    > private System.Data.Sql Client.SqlDataA dapter sqlDataAdapter1 ;
    > public System.Windows. Forms.DataGridT ableStyle dgtsproducts;
    > public System.Windows. Forms.DataGridT extBoxColumn dgtbcProducts;
    > public System.Windows. Forms.DataGridT ableStyle dgtsProducts;
    > public DataGridComboBo xColumn dgcbcProducts;
    > public System.Data.Sql Client.SqlDataA dapter daProducts;
    > public System.Data.Dat aSet dsProducts;
    >
    >
    > private System.Componen tModel.Containe r components = null;
    >
    > public frmproducts()
    > {
    > InitializeCompo nent();
    >
    > //Set datagrid preferred height to comboboxheight
    >
    > dgproducts.Pref erredRowHeight = dgcbcProducts.C ombobox.Height + 1;
    > //dgcbcProducts is the problem object
    >
    > }
    >
    >
    >
    >
    >[/color]

    Comment

    Working...