Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagrid which is MANUALLY created through a similar code

C#
for (int row= 0; row< totRows; row++)
{
    dynamic newRow = new ExpandoObject();
    for (int col = 0; col < numTotCol; col++)
    {
        string strColumnHeader = columnLabels[col].Replace(' ', '_');
        ((IDictionary<String, Object>)newRow)[strColumnHeader] = ...
    }
    dtgResults.Items.Add(newRow);
}



what I need now is something that in MS Excel is described as mergin columns.
In short I need to add a "comment line" when necessary. That line has to be way larger but has not to change the other columns. That is it has to accomodate on more columns.

What I have tried:

What I have tried is to use the d DataGridCell_Load event.
I thought about something like that:

C#
if (row == 3 && column == 0)
{
	cell.Width = 300;
	cell.Content = "AAAAA A A AA A A A A A AQ A A AA A A A A A A";
}



but that didn't change anything: the line in question has the first row which is always the same width.

Thank you in advance.
Posted
Updated 17-May-16 0:15am

1 solution

Do not create the datagrid manually but use ObservableCollection.
This way you can easily manipulate values in code behind, changes work both ways.
Here is an example for a ListView:
C#
private ObservableCollection<MyListViewItem> myListViewItems = new ObservableCollection<MyListViewItem>();

ListView1.ItemsSource = this.myListViewItems;

public class MyListViewItem     
{
    public MyListViewItem()
    {
    }

    public MyListViewItem(string name, string value, string group, string tag, SolidColorBrush color)
    {
        this.Name = name;
        this.Value = value;
        this.Group = group;
        this.Tag = tag;
        this.StatusColor = color;
    }

    public string Name { get; set; }

    public string Value { get; set; }

    public string Group { get; set; }

    public string Tag { get; set; }

    public SolidColorBrush StatusColor { get; set; }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900