DataGrid Problem

  • Thread starter Thread starter Trey
  • Start date Start date
T

Trey

I am trying to create and load a datagrid at runtime. I am not having any
luck. The Datagrid shows up and one column which is about 50 wide shows up
with no header. What am I doing wrong? Here is my code.

dgcColLeft1 = new DataGridTextBoxColumn();
dgtsGridLeft = new DataGridTableStyle();
grdLeft = new DataGrid();

// Make the Grid
grdLeft.Location = new System.Drawing.Point(6, 6);
grdLeft.Size = new System.Drawing.Size(300, 300);
grdLeft.Dock = DockStyle.Fill;
grdLeft.CaptionVisible = false;
grdLeft.DataMember = "";
grdLeft.DataSource = dv; //dataview
grdLeft.Name = "GridLeft";
grdLeft.TableStyles.Add(dgtsGridLeft); // add table styles

// make the styles
dgtsGridLeft.DataGrid = this.grdLeft;
dgtsGridLeft.MappingName = "Services";
dgtsGridLeft.GridColumnStyles.Add(dgcColLeft1); // add the column

// make the column
dgcColLeft1.Format = "";
dgcColLeft1.FormatInfo = null;
dgcColLeft1.HeaderText = "Test this";
dgcColLeft1.MappingName = "ColumnLeft1Name";
dgcColLeft1.NullText = "";
dgcColLeft1.Width = 125;
 
Make sure the DataTable, which the DataGrid's datasource- dv is based on,
has TableName "Sevices" and there is a DataColumn called "ColumnLeft1Name"
in the DataTable.

It is obvious for me that when data binding occurs, the datagrid does not
find mapped table name, or mapped column name, thus you get a blank column
in grid.
 
OK, try this:

Move grdLeft.DataSource further down, to after GridColumns and
GridTableStyle are programmingly defined. The problem could be: you set
DataSource too early that data binding occurs before your tablestyle and
gridColumn is created!
 
Back
Top