Hi
I have some data and i want to group one column or show as merge cell in grid Like bellow
From :
//------------------------------------------------------Show in grid like bellow
I have some data and i want to group one column or show as merge cell in grid Like bellow
From :
Id | Name | ItemToBuy |
1 | mike | Toshiba portage |
1 | mike | Dell Latitude |
2 | nancy | Toshiba portage |
2 | nancy | Sony vioa |
3 | rosa | Asus |
3 | rosa | Hp |
4 | farid | Sony vioa |
Id | Name | ItemToBuy |
1 | mike | Toshiba portage |
Dell Latitude | ||
2 | nancy | Toshiba portage |
Sony vioa | ||
3 | rosa | Asus |
Hp | ||
4 | farid | Sony vioa //---------------------------------------- i dont want to use Hierarchical structure |
7 Answers, 1 is accepted
0
Accepted
Hi ali,
Thank you for writing.
You can create this functionality by going through all cells and apply your custom style for the cells that you want, for example:
Attached is a sample project that contains the code above.
This topic is also discussed in the following forum thread: http://www.telerik.com/community/forums/winforms/gridview/how-to-merge-cell.aspx
I hope this information helps. If you have further questions, feel free to write back
Regards,
Anton
the Telerik team
Thank you for writing.
You can create this functionality by going through all cells and apply your custom style for the cells that you want, for example:
private
void
MergeCell(RadGridView radGridView1,
int
[] idx)
{
GridViewRowInfo Prev =
null
;
foreach
(GridViewRowInfo item
in
radGridView1.Rows)
{
if
(Prev !=
null
)
{
string
firstCellText =
string
.Empty;
string
secondCellText =
string
.Empty;
foreach
(
int
i
in
idx)
{
GridViewCellInfo firstCell = Prev.Cells[i];
GridViewCellInfo secondCell = item.Cells[i];
firstCellText = (firstCell !=
null
&& firstCell.Value !=
null
? firstCell.Value.ToString() :
string
.Empty);
secondCellText = (secondCell !=
null
&& secondCell.Value !=
null
? secondCell.Value.ToString() :
string
.Empty);
firstCell.Style.CustomizeBorder =
true
;
firstCell.Style.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
firstCell.Style.BorderLeftColor = Color.FromArgb(209, 225, 245);
firstCell.Style.BorderRightColor = Color.FromArgb(209, 225, 245);
secondCell.Style.CustomizeBorder =
true
;
secondCell.Style.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
secondCell.Style.BorderLeftColor = Color.FromArgb(209, 225, 245);
secondCell.Style.BorderRightColor = Color.FromArgb(209, 225, 245);
secondCell.Style.BorderTopColor = Color.FromArgb(209, 225, 245);
secondCell.Style.BorderBottomColor = Color.FromArgb(209, 225, 245);
if
(firstCell.Style.BorderTopColor != Color.Transparent)
{
firstCell.Style.BorderTopColor = Color.FromArgb(209, 225, 245);
}
if
(firstCellText == secondCellText)
{
firstCell.Style.BorderBottomColor = Color.Transparent;
secondCell.Style.BorderTopColor = Color.Transparent;
secondCell.Style.ForeColor = Color.Transparent;
}
else
{
Prev = item;
break
;
}
}
}
else
{
Prev = item;
}
}
}
Attached is a sample project that contains the code above.
This topic is also discussed in the following forum thread: http://www.telerik.com/community/forums/winforms/gridview/how-to-merge-cell.aspx
I hope this information helps. If you have further questions, feel free to write back
Regards,
Anton
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
ali
Top achievements
Rank 1
answered on 10 Oct 2012, 08:46 PM
Hi Anton
thank you for answering and I hope you are successful in your life.
thank you for answering and I hope you are successful in your life.
0
Hi Ali,
I am glad to hear that everything is OK. Thank you very much for the nice words.
All the best,
Anton
the Telerik team
I am glad to hear that everything is OK. Thank you very much for the nice words.
All the best,
Anton
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
ali
Top achievements
Rank 1
answered on 18 Oct 2012, 02:01 PM
Hi Anton
i want to use alternative row color in my grid that this method is not work
plz help me
i want to use alternative row color in my grid that this method is not work
plz help me
0
Hi Ali,
Thank you for writing back.
Presently, you can achieve cell merge only by using the Html definition. You can read more about it in the online documentation. All other solutions, including the one provided in my previous post are workaround, and there is no way to make provided workaround to work with alternate row color.
I hope this information helps.
Regards,
Anton
the Telerik team
Thank you for writing back.
Presently, you can achieve cell merge only by using the Html definition. You can read more about it in the online documentation. All other solutions, including the one provided in my previous post are workaround, and there is no way to make provided workaround to work with alternate row color.
I hope this information helps.
Regards,
Anton
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
ali
Top achievements
Rank 1
answered on 20 Oct 2012, 06:32 AM
Hi Anton thanks for replay
can you plz change your sample that sent to me with this HTML method?
i want use row number too
and i want that row number show not in first cell but in middle like this
plz see my attach file
can you plz change your sample that sent to me with this HTML method?
i want use row number too
and i want that row number show not in first cell but in middle like this
plz see my attach file
0
Accepted
Hi Ali,
Thank you for writing back.
In my last post I meant to say that merging in RadGridView is not possible and the only merge scenario that is supported is the one described in the HTML view definition article - in the first image in the article see how the City and Country are merged when you place the Phone column underneath the ID and Name. This is the only merging scenario supported by RadGridView and your case cannot be achieved with HTML view definition.
At first I created a highly custom solution that seems to be working without further customization, however, alternating row colors, row numbers, will not work it with.
Another thing that I can offer is to merge your data in your data source and modify the cell text. Attached you can find a sample, where I have merged the ItemToBuy for each user, by separating the different records with a semicolon. This way, the cell value is the concatenated string of all these values, and then, I am using CellFormatting to split those values and to set the cell text.
In this case, you can also set row numbers and use alternating row colors.
If this does not work for you, I am afraid that there is nothing else that I can offer.
Let us know if you have any other questions.
All the best,
Anton
the Telerik team
Thank you for writing back.
In my last post I meant to say that merging in RadGridView is not possible and the only merge scenario that is supported is the one described in the HTML view definition article - in the first image in the article see how the City and Country are merged when you place the Phone column underneath the ID and Name. This is the only merging scenario supported by RadGridView and your case cannot be achieved with HTML view definition.
At first I created a highly custom solution that seems to be working without further customization, however, alternating row colors, row numbers, will not work it with.
Another thing that I can offer is to merge your data in your data source and modify the cell text. Attached you can find a sample, where I have merged the ItemToBuy for each user, by separating the different records with a semicolon. This way, the cell value is the concatenated string of all these values, and then, I am using CellFormatting to split those values and to set the cell text.
In this case, you can also set row numbers and use alternating row colors.
If this does not work for you, I am afraid that there is nothing else that I can offer.
Let us know if you have any other questions.
All the best,
Anton
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.