?
Solved

Not Getting All Rows in my DataGrid when I add a DataGridTableStyle

Posted on 2005-03-15
2
Medium Priority
?
217 Views
Last Modified: 2010-04-16

I am trying to add two columns to a datagrid and then format those columns using the DataGridTableStyle.  I am using a DataSource that I populate by hand .  If I don't use the DataGridTableStyle, I get both columns, but they are not formatted the way I want them to be.  If I then add the DataGridTableStyle, I only get one column which is formatted the way i want it to be.  Here is my code:

  dataGrid1.BeginInit();

  Hashtable eventsList = new Hashtable();
  DataSources.GetEvents(ref eventsList);

  dsEvents.Tables.Add("EventsTable");
  dsEvents.Tables[0].Columns.Add();
  dsEvents.Tables[0].Columns.Add();
  dsEvents.Tables[0].Columns[0].ColumnName = "Event Id";
  dsEvents.Tables[0].Columns[1].ColumnName = "Description";
  foreach (Object o in eventsList.Keys)
  {
      string [] vals = new string[2];
      vals[0] = o.ToString();
      vals[1] = (string)eventsList[o];
      dsEvents.Tables[0].Rows.Add(vals);
  }

  dataGrid1.DataSource = dsEvents.Tables["EventsTable"];
  DataGridTableStyle ts = new DataGridTableStyle();
  ts.MappingName = dsEvents.Tables["EventsTable"].TableName;

  DataGridColumnStyle cs1 = new DataGridTextBoxColumn();
  cs1.MappingName = "eventId";
  cs1.HeaderText = "EventID";
  cs1.Width = 100;
  ts.GridColumnStyles.Add(cs1);

  DataGridColumnStyle cs2 = new DataGridTextBoxColumn();
  cs2.MappingName = "description";
  cs2.HeaderText = "Description";
  cs2.Width = 300;
  ts.GridColumnStyles.Add(cs2);

  dataGrid1.TableStyles.Add(ts);
  dataGrid1.EndInit();


When this code is executed, instead of getting two columns (EventID and Description), I get just one column (Description).  If I remove the table style from the datagrid, I get both columns.  
0
Comment
Question by:mromeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
dungla earned 600 total points
ID: 13546566
change
-->cs1.MappingName = "eventId";
to
--> cs1.MappingName = "Event Id";

Because your source table have colum with name "Event Id" not "eventId"
0
 

Author Comment

by:mromeo
ID: 13546635
Ah yes...the column name needs to match the mapping name.  I should have seen that. Thank you!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question