This is a migrated thread and some comments may be shown as answers.

Custom Cells

4 Answers 195 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frederico Fernandes
Top achievements
Rank 1
Frederico Fernandes asked on 04 Aug 2011, 12:00 PM
Hi,

is it possible to build a radgrid with the structure of the attached file?

I want a mix of checkboxs and labels at the same cell, except from row one which must be two labels.
I've seen a few examples of custom columns with the progress bar and a button, thus i can't get it to work.

Thanks in advance,
SF

4 Answers, 1 is accepted

Sort by
0
Frederico Fernandes
Top achievements
Rank 1
answered on 05 Aug 2011, 07:47 PM
Hi,

managed to  build a solution that works fine:

//First Column
this.radGridView1.Columns.Add("#");
this.radGridView1.Columns.Add("#V");
 
int num = 3;
//Add as much columns as need by the int num
for (int i = 1; i <= num; i++)
{
    GridViewCheckBoxColumn ch1 = new GridViewCheckBoxColumn();
    ch1.FieldName="V"+i; //diferente unique name for the column
    ch1.HeaderText = "V"; // same name in all columns
    this.radGridView1.Columns.Add(ch1);
 
    GridViewTextBoxColumn tb1 = new GridViewTextBoxColumn();
    tb1.FieldName = "P" + i; //diferente unique name for the column
    tb1.HeaderText = "P"; // same name in all columns
    this.radGridView1.Columns.Add(tb1);
}
 
ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
 
 
//Group First column and define sub-columns
view.ColumnGroups.Add(new GridViewColumnGroup("First"));
view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["#"]);
view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["#V"]);
 
 
//Create Column Groups
for (int i = 1; i <= num; i++)
{
    view.ColumnGroups.Add(new GridViewColumnGroup("C "+i));
    //view.ColumnGroups.Add(new GridViewColumnGroup("C "+(i+1)));
}
 
 
//Create Sub-Columns
for (int i = 1; i <= num; i++ )
{
    view.ColumnGroups[i].Rows.Add(new GridViewColumnGroupRow());
    view.ColumnGroups[i].Rows[0].Columns.Add(this.radGridView1.Columns["V"+i]);
    view.ColumnGroups[i].Rows[0].Columns.Add(this.radGridView1.Columns["P"+i]);
}
 
radGridView1.ViewDefinition = view;
 
//Create Checkbox
CheckBox cb = new CheckBox();
cb.Checked = true; //define value
radGridView1.Rows.Add("1" , "3", cb.Checked, "30%", cb.Checked, "35%", cb.Checked, "40%");
radGridView1.Rows.Add("2", "3", cb.Checked, "50%", cb.Checked, "55%", cb.Checked, "60%");

Is it possible to change ColumnGroups header text orientation ?

Thanks,
Sílvio Fernandes
0
Accepted
Stefan
Telerik team
answered on 09 Aug 2011, 04:07 PM
Hi Silvio,

Thank you for writing.

You can change the orientation of the text in the header row by subscribing to the ViewCellFormatting event and setting the TextOrientation property of the GridColumnGroupCellElement to Vertical:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridColumnGroupCellElement cell = e.CellElement as GridColumnGroupCellElement;
    if (cell != null)
    {
        cell.TextOrientation = Orientation.Vertical;
    }
}

This will change the text orientation. However, you might need to increase the header row height in order to accommodate the text. This can be done by setting the RowSpan property of the desired column group. Here is the change that I have made to your code in order to increase the row span:
GridViewColumnGroup columnGroup = new GridViewColumnGroup("First");
columnGroup.RowSpan = 50;
view.ColumnGroups.Add(columnGroup);

I hope that you find this information helpful.
 
Regards,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Frederico Fernandes
Top achievements
Rank 1
answered on 09 Aug 2011, 11:10 PM
Thank you Stefan,

I got to the solution by this

private void gridAssignments_ViewCellFormatting(object sender, CellFormattingEventArgs e)
 {
      GridHeaderCellElement element = sender as GridHeaderCellElement;
        if (element != null)
            {
                element.TextOrientation = Orientation.Vertical;
            }
}

but your suggestion fits best.

Still, i have a another group of questions if you can help:

1 - By clicking the groud with the name "C1", how can i "Console.Writeline" this text?
2 - Strange thing. If i click at C1, and then C2, both of them remain selected, i would like to be able when clicking C2, after clicking C1, it unselects C1 and leaves C2 selected.

Thanks in advance,
Sílvio Fernandes
0
Accepted
Stefan
Telerik team
answered on 11 Aug 2011, 03:00 PM
Hello Silvio,

Thank you for writing.

1. In order to print the cell value when the group cell is clicked, subscribe to the CellClick event and check the cell type. If it is GridColumnGroupCellElement, print the cell value:
void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
    GridColumnGroupCellElement cell = sender as GridColumnGroupCellElement;
    if (cell != null)
    {
        Console.WriteLine(cell.Value.ToString());
    }
}

2. It seems that we currently experience an issue with the states of this type of cell. Unfortunately, I am not able to provide you with work around for this issue. I am adding this into our PITS system. Please follow this link, where you can add your vote for this issue, in order to increase its priority. We will do our best to fit this in our plans for the upcoming Service Pack.

I have updated your Telerik points for this report.

Should you have any other questions, do not hesitate to contact us.
 
Greetings,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
GridView
Asked by
Frederico Fernandes
Top achievements
Rank 1
Answers by
Frederico Fernandes
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or