Assign a table style to child tables for datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a dataset populated using an XML file. The schema has hierarchical
components. Let's say <a><b></b></a>.

I have created a datagrid and I have assigned a datastyle and then
gridcolumnstyle for all columns at the parent level.
I have created a datastyle for every child level and I have assigned also
gridcolumn styles to the components.

When I run the program, I have the grid displayed and the + symbol next to
my rows. When I expand this symbol, I have the name of the child table.
However, when I clicked on this name, I have this exception raised:

System.InvalidOperationException: The '' DataGridColumnStyle cannot be used
because it is not associated with a Property or Column in the DataSource.

I have a big red cross in the datagrid, and one element from this child
table displayed.

I have this code for the datagrid:
--
this.dataGrid.AlternatingBackColor = System.Drawing.Color.LightBlue;
this.dataGrid.DataMember = "";
this.dataGrid.DataSource = this.datasetTestCases.automated_test_case;
this.dataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid.Location = new System.Drawing.Point(5, 65);
this.dataGrid.Name = "dataGrid";
this.dataGrid.PreferredColumnWidth = 80;
this.dataGrid.Size = new System.Drawing.Size(685, 330);
this.dataGrid.TabIndex = 2;
this.dataGrid.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {
this.DataGridTableStyleMain,
this.dataGridTableStyleXCS,
this.dataGridTableStyleDB,
this.dataGridTableStyleOpt});
--

The dataGridTableStyleXCS, dataGridTableStyleDB, dataGridTableStyleOpt are
for every child table.

Here is the definition of one of them:
--
this.dataGridTableStyleXCS.AlternatingBackColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyleXCS.DataGrid = this.dataGrid;
this.dataGridTableStyleXCS.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumnXCS1,
this.dataGridTextBoxColumnXCS2,
this.dataGridTextBoxColumnXCS3});
this.dataGridTableStyleXCS.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyleXCS.MappingName = "automated_test_case_xcs";
this.dataGridTableStyleXCS.ReadOnly = true;
--

The mapping name correspond to the name of the child table, therefore I do
not understand what's going on.

Moreover, everything was fine before I assigned datagridstyles.

Thank you for your help.
 
Hello,

Each column style also has the MappingName property which should be set to
the name of the DataTable column this column style should apply to.
 
Hello,

Thank you for your reply.

However I was doing so. Here is an example of my code each column.

--
this.dataGridTextBoxColumnXCS1.Alignment =
System.Windows.Forms.HorizontalAlignment.Center;
this.dataGridTextBoxColumnXCS1.Format = "";
this.dataGridTextBoxColumnXCS1.FormatInfo = null;
this.dataGridTextBoxColumnXCS1.HeaderText = "Server";
this.dataGridTextBoxColumnXCS1.MappingName = "server";
this.dataGridTextBoxColumnXCS1.ReadOnly = true;
this.dataGridTextBoxColumnXCS1.Width = 75;
--

I have done this using the gui ide (not programming it by myself). What I
found weird is that the gui shows me this mapping names, this means that the
data can be retrieved. Why can't I display it?
The exception error does not mention the name of the datagrid column to be
displayed, it is only ", is that maybe a clue?

Thank you.
 
I have just noticed that in my "task list", there is one which is "Method
System.Windows.Forms.Form.InitializeDataSet not found."
However, according to me I initialize my dataset by doing this

--
datasetTestCases.ReadXml(xmlFilePath)
--

If I try to write a method with the same name, it says that it is exists
already. Same issue if I want to override it.

Is this "task" related to my problem?

Thank you for your help.
 
Back
Top