Create new winform datagrid

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

    Create new winform datagrid

    Everyone:

    Using C#, I'm trying to create a datagrid on a winform programatically .
    I placed the datagrid and the form and named it CHGrid. Here's the
    code I'm using:

    // Get and bind the data.
    QarBusTier.Defe ctFoundLocation DFL = new
    QarBusTier.Defe ctFoundLocation ();
    System.Data.Dat aTable DFLTable = DFL.LoadAll();

    CHGrid.DataSour ce = DFLTable;

    // Set the data grid style.
    DataGridTableSt yle ts1 = new DataGridTableSt yle();
    ts1.MappingName = "Customers" ;

    // Set the datagrid style.
    CHGrid.Top = 50;
    CHGrid.Left = 200;
    CHGrid.Width = 350;
    CHGrid.Height= 200;
    CHGrid.ForeColo r = System.Drawing. Color.Black;
    CHGrid.BackColo r = System.Drawing. Color.Beige;

    // Create column.
    DataGridBoolCol umn myDataCol = new DataGridBoolCol umn();
    myDataCol.Mappi ngName = "DefectFoundLoc ationId";
    myDataCol.Heade rText = "My New Column";
    myDataCol.Width = 100;
    ts1.GridColumnS tyles.Add(myDat aCol);

    CHGrid.TableSty les.Add(ts1);

    The DFL.LoadAll() just gets all the data from a table. My grid is
    populated with the 4 columns being returned from DFL.LoadAll() but the
    column I create is not being displayed.

    I want to display only the column(s) I create and not have the grid
    auto-populate.

    Thanks for the help,
    Dale Williams
  • Dmytro Lapshyn [MVP]

    #2
    Re: Create new winform datagrid

    Hi Dale,

    Define all the column and table styles FIRST and bind the grid to the data
    source SECOND (I'd also recommend that you do the binding with the grid's
    SetDataBinding method.

    --
    Sincerely,
    Dmytro Lapshyn [Visual Developer - Visual C# MVP]


    "Dale Williams" <dwilliams@yf.c om> wrote in message
    news:eWRY$3MBGH A.2356@tk2msftn gp13.phx.gbl...[color=blue]
    > Everyone:
    >
    > Using C#, I'm trying to create a datagrid on a winform programatically . I
    > placed the datagrid and the form and named it CHGrid. Here's the code I'm
    > using:
    >
    > // Get and bind the data.
    > QarBusTier.Defe ctFoundLocation DFL = new QarBusTier.Defe ctFoundLocation ();
    > System.Data.Dat aTable DFLTable = DFL.LoadAll();
    >
    > CHGrid.DataSour ce = DFLTable;
    >
    > // Set the data grid style.
    > DataGridTableSt yle ts1 = new DataGridTableSt yle();
    > ts1.MappingName = "Customers" ;
    >
    > // Set the datagrid style.
    > CHGrid.Top = 50;
    > CHGrid.Left = 200;
    > CHGrid.Width = 350;
    > CHGrid.Height= 200;
    > CHGrid.ForeColo r = System.Drawing. Color.Black;
    > CHGrid.BackColo r = System.Drawing. Color.Beige;
    >
    > // Create column.
    > DataGridBoolCol umn myDataCol = new DataGridBoolCol umn();
    > myDataCol.Mappi ngName = "DefectFoundLoc ationId";
    > myDataCol.Heade rText = "My New Column";
    > myDataCol.Width = 100;
    > ts1.GridColumnS tyles.Add(myDat aCol);
    >
    > CHGrid.TableSty les.Add(ts1);
    >
    > The DFL.LoadAll() just gets all the data from a table. My grid is
    > populated with the 4 columns being returned from DFL.LoadAll() but the
    > column I create is not being displayed.
    >
    > I want to display only the column(s) I create and not have the grid
    > auto-populate.
    >
    > Thanks for the help,
    > Dale Williams[/color]

    Comment

    Working...