Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2005-03-15
Medium Priority
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:


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

  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];

  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;

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


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.  
Question by:mromeo
LVL 13

Accepted Solution

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

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

Author Comment

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

Featured Post

Independent Software Vendors: 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

571 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