From: maark on
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 [MVP]" wrote:

> 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" <maark(a)discussions.microsoft.com> wrote in message
> news:F7CE02F5-E14C-4FB1-9916-8E5450DBE008(a)microsoft.com...
> > 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[i].code;
> > dr["Number"] = this.resultRows[i].number;
> > dr["Street"] = this.resultRows[i].street;
> > dr["City"] = this.resultRows[i].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
> >
>
>
>