G
Guest
Platform : WinCE 4.2, .NET CF C#
I am trying to use a DataGrid control to display some data but only 2 cells
(one over the other) in the top left corner of the control are displayed.
The bottom cell has a small black triangle in it. I think they are header
cells because I have set the HeaderBackColor property to green. I have
stepped through the code but cannot see what the problem is. Any ideas would
be greatly appreciated.
Here is a code snippet:
public class ShowCodes : Form
{
private DataGrid gridCodes;
private DataSet dsCodes;
private DataTable dtCodes;
private bool bGridStyleSet = false;
private CodeInfo[] resultRows;
public struct CodeInfo
{
public string code;
public string number;
public string street;
public string city;
public string province;
}
public ShowCodes()
{
this.DisplayGridResult();
}
private void DisplayGridResult()
{
this.InitGrid();
/*
* Calculate the size of the grid and the panel based on the
* number of rows returned from the search.
*/
this.gridCodes.Size = new Size(760,200);
this.gridCodes.Location = new Point(40, 100);
this.gridCodes.Show();
}
private void InitGrid()
{
this.gridCodes = new DataGrid();
this.SetGridStyle();
this.LoadData();
this.gridCodes.DataSource = this.dsCodes;
this.gridCodes.Visible = true;
this.gridCodes.SelectionForeColor = Color.Red;
this.gridCodes.SelectionBackColor = Color.DarkBlue;
this.gridCodes.BackColor = Color.White
this.gridCodes.ForeColor = Color.Black;
this.gridCodes.HeaderForeColor = Color.Black;
this.gridCodes.HeaderBackColor = Color.Green;
this.gridCodes.Enabled = true;
this.gridCodes.Click += new EventHandler(gridCodes_Click);
this.gridCodes.Parent = this;
this.Controls.Add(this.gridCodes);
}
private void SetGridStyle()
{
DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "CodesTable";
// Code Column
DataGridTextBoxColumn codeColStyle = new DataGridTextBoxColumn();
codeColStyle.MappingName = "Code";
codeColStyle.HeaderText = "postal_code";
codeColStyle.Width = 80;
gridStyle.GridColumnStyles.Add(codeColStyle);
// Number Column
DataGridTextBoxColumn numberColStyle = new
DataGridTextBoxColumn();
numberColStyle.MappingName = "Number";
numberColStyle.HeaderText = "number_range";
numberColStyle.Width = 100;
gridStyle.GridColumnStyles.Add(numberColStyle);
// Street Column
DataGridTextBoxColumn streetColStyle = new
DataGridTextBoxColumn();
streetColStyle.MappingName = "Street";
streetColStyle.HeaderText = "street name";
streetColStyle.Width = 300;
gridStyle.GridColumnStyles.Add(streetColStyle);
// City Column
DataGridTextBoxColumn cityColStyle = new DataGridTextBoxColumn();
cityColStyle.MappingName = "City";
cityColStyle.HeaderText = "city";
cityColStyle.Width = 160;
gridStyle.GridColumnStyles.Add(cityColStyle);
this.gridCodes.TableStyles.Add(gridStyle);
}
private void LoadData()
{
this.dsCodes = new DataSet("dataSetCodes");
this.dtCodes = new DataTable("CodesTable");
DataColumn cCode = new DataColumn("Code");
DataColumn cNumber = new DataColumn("Number");
DataColumn cStreet = new DataColumn("Street");
DataColumn cCity = new DataColumn("City");
this.dtCodes.Columns.Add(cCode);
this.dtCodes.Columns.Add(cNumber);
this.dtCodes.Columns.Add(cStreet);
this.dtCodes.Columns.Add(cCity);
// Add the dataTable to the dataSet.
this.dsCodes.Tables.Add(this.dtCodes);
// Get the Results
this.GetPostalCodes();
this.dtCodes.Clear();
DataRow dr;
// Add the rows of data.
for (int i = 0; i < this.resultRows.Length; i++)
{
dr = this.dtCodes.NewRow();
dr["Code"] = this.resultRows.code;
dr["Number"] = this.resultRows.number;
dr["Street"] = this.resultRows.street;
dr["City"] = this.resultRows.city;
this.dtCodes.Rows.Add(dr);
}
}
// Hard-coded data
private void GetCodes()
{
this.resultRows = new CodeInfo[2];
this.resultRows[0] = new CodeInfo();
this.resultRows[0].city = "montreal";
this.resultRows[0].code = "A1AS4S";
this.resultRows[0].number = "10-20";
this.resultRows[0].street = "Main Street";
this.resultRows[0].province = "Quebec";
this.resultRows[1] = new CodeInfo();
this.resultRows[1].city = "montreal";
this.resultRows[1].code = "A1AS4S";
this.resultRows[1].number = "20-30";
this.resultRows[1].street = "Main Street";
this.resultRows[1].province = "Quebec";
}
}
TIA
Mark
I am trying to use a DataGrid control to display some data but only 2 cells
(one over the other) in the top left corner of the control are displayed.
The bottom cell has a small black triangle in it. I think they are header
cells because I have set the HeaderBackColor property to green. I have
stepped through the code but cannot see what the problem is. Any ideas would
be greatly appreciated.
Here is a code snippet:
public class ShowCodes : Form
{
private DataGrid gridCodes;
private DataSet dsCodes;
private DataTable dtCodes;
private bool bGridStyleSet = false;
private CodeInfo[] resultRows;
public struct CodeInfo
{
public string code;
public string number;
public string street;
public string city;
public string province;
}
public ShowCodes()
{
this.DisplayGridResult();
}
private void DisplayGridResult()
{
this.InitGrid();
/*
* Calculate the size of the grid and the panel based on the
* number of rows returned from the search.
*/
this.gridCodes.Size = new Size(760,200);
this.gridCodes.Location = new Point(40, 100);
this.gridCodes.Show();
}
private void InitGrid()
{
this.gridCodes = new DataGrid();
this.SetGridStyle();
this.LoadData();
this.gridCodes.DataSource = this.dsCodes;
this.gridCodes.Visible = true;
this.gridCodes.SelectionForeColor = Color.Red;
this.gridCodes.SelectionBackColor = Color.DarkBlue;
this.gridCodes.BackColor = Color.White
this.gridCodes.ForeColor = Color.Black;
this.gridCodes.HeaderForeColor = Color.Black;
this.gridCodes.HeaderBackColor = Color.Green;
this.gridCodes.Enabled = true;
this.gridCodes.Click += new EventHandler(gridCodes_Click);
this.gridCodes.Parent = this;
this.Controls.Add(this.gridCodes);
}
private void SetGridStyle()
{
DataGridTableStyle gridStyle = new DataGridTableStyle();
gridStyle.MappingName = "CodesTable";
// Code Column
DataGridTextBoxColumn codeColStyle = new DataGridTextBoxColumn();
codeColStyle.MappingName = "Code";
codeColStyle.HeaderText = "postal_code";
codeColStyle.Width = 80;
gridStyle.GridColumnStyles.Add(codeColStyle);
// Number Column
DataGridTextBoxColumn numberColStyle = new
DataGridTextBoxColumn();
numberColStyle.MappingName = "Number";
numberColStyle.HeaderText = "number_range";
numberColStyle.Width = 100;
gridStyle.GridColumnStyles.Add(numberColStyle);
// Street Column
DataGridTextBoxColumn streetColStyle = new
DataGridTextBoxColumn();
streetColStyle.MappingName = "Street";
streetColStyle.HeaderText = "street name";
streetColStyle.Width = 300;
gridStyle.GridColumnStyles.Add(streetColStyle);
// City Column
DataGridTextBoxColumn cityColStyle = new DataGridTextBoxColumn();
cityColStyle.MappingName = "City";
cityColStyle.HeaderText = "city";
cityColStyle.Width = 160;
gridStyle.GridColumnStyles.Add(cityColStyle);
this.gridCodes.TableStyles.Add(gridStyle);
}
private void LoadData()
{
this.dsCodes = new DataSet("dataSetCodes");
this.dtCodes = new DataTable("CodesTable");
DataColumn cCode = new DataColumn("Code");
DataColumn cNumber = new DataColumn("Number");
DataColumn cStreet = new DataColumn("Street");
DataColumn cCity = new DataColumn("City");
this.dtCodes.Columns.Add(cCode);
this.dtCodes.Columns.Add(cNumber);
this.dtCodes.Columns.Add(cStreet);
this.dtCodes.Columns.Add(cCity);
// Add the dataTable to the dataSet.
this.dsCodes.Tables.Add(this.dtCodes);
// Get the Results
this.GetPostalCodes();
this.dtCodes.Clear();
DataRow dr;
// Add the rows of data.
for (int i = 0; i < this.resultRows.Length; i++)
{
dr = this.dtCodes.NewRow();
dr["Code"] = this.resultRows.code;
dr["Number"] = this.resultRows.number;
dr["Street"] = this.resultRows.street;
dr["City"] = this.resultRows.city;
this.dtCodes.Rows.Add(dr);
}
}
// Hard-coded data
private void GetCodes()
{
this.resultRows = new CodeInfo[2];
this.resultRows[0] = new CodeInfo();
this.resultRows[0].city = "montreal";
this.resultRows[0].code = "A1AS4S";
this.resultRows[0].number = "10-20";
this.resultRows[0].street = "Main Street";
this.resultRows[0].province = "Quebec";
this.resultRows[1] = new CodeInfo();
this.resultRows[1].city = "montreal";
this.resultRows[1].code = "A1AS4S";
this.resultRows[1].number = "20-30";
this.resultRows[1].street = "Main Street";
this.resultRows[1].province = "Quebec";
}
}
TIA
Mark