DataGrid only displays header cells

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

Ilya Tumanov [MS]

You can't set grid's data source to a DataSet on CF.
Only DataView or a DataTable (via default DataView) will work.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.



maark said:
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
 
P

Peter Foot [MVP]

You are sure the mapping names you have defined exactly match those of
fields in the datasource e.g.
codeColStyle.MappingName = "Code";
codeColStyle.HeaderText = "postal_code";
Are these the correct way round - it looks to me as if postal_code should be
your field name and Code is your display text...

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

maark said:
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
 
G

Guest

Thank you - By setting the DataGrid's DataSource to a DataView the grid now
displays correctly.
BTW - I believe that I had used a DataSet with the DataGrid a couple of
months ago so I am interested as to why it is not working now?

Mark

Ilya Tumanov said:
You can't set grid's data source to a DataSet on CF.
Only DataView or a DataTable (via default DataView) will work.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.



maark said:
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

Ilya Tumanov [MS]

That might be - in a desktop application. It never worked on CF.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Thread-Topic: DataGrid only displays header cells
thread-index: AcUOI6qrs1pe5juNRRma6rT3vnHLJg==
X-WBNR-Posting-Host: 199.231.49.128
From: "=?Utf-8?B?bWFhcms=?=" <[email protected]>
References: <[email protected]>
Subject: Re: DataGrid only displays header cells
Date: Tue, 8 Feb 2005 13:18:00 -0800
Lines: 193
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:70734
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Thank you - By setting the DataGrid's DataSource to a DataView the grid now
displays correctly.
BTW - I believe that I had used a DataSet with the DataGrid a couple of
months ago so I am interested as to why it is not working now?

Mark

Ilya Tumanov said:
You can't set grid's data source to a DataSet on CF.
Only DataView or a DataTable (via default DataView) will work.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.



maark said:
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


 
G

Guest

Yes the mapping names are correct.
The reason that they appear suspicious in the example is that for the
HeaderText field I use a localized string resoource and, in order to simplify
the example, I removed the method call I use to access the resource and
replaced it with the resource ID - which I turned into a string.

Peter Foot said:
You are sure the mapping names you have defined exactly match those of
fields in the datasource e.g.
codeColStyle.MappingName = "Code";
codeColStyle.HeaderText = "postal_code";
Are these the correct way round - it looks to me as if postal_code should be
your field name and Code is your display text...

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

maark said:
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

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top