Hi,
Could You please provide Theme for WinForms style (I couldn't found one).
I was trying to achieve that using Visual Style Builder, but effect wasn't well rounded, even that I've spent some time on that.
The problem I'm facing is that I'm using RadGridView as an extension for a WinForm based project and it don't fit in well.
Another issue is that WinForms looks a little different on differents OS (XP, Windows 7) while RadGridView looks always exactly the same.
Regards.
18 Answers, 1 is accepted

The closest you're going to get without making on in VSB is the Window7 theme. I have attached a screenshot of a RadgridView with this theme.
However, I'd stress that part of the point of Telerik controls is that they do look "better" then the standard WinForms controls and the consistancy that you can get with themes is part of this.
Hope that helps, but let me know if you have any questions
Richard

Hi
Thanks for tip but I've already know about provided themes, Windows 7 as well - I was trying to create win forms theme starting from that as a pattern with out a good result. What I'm truing to point is a lack of consistency, when you use telerik in winforms host.
Regards.

Sorry to hear that didn't help. As you know, the only way to make your own is by using the Visual Style builder. The Telerik grids will always look the same under different operating systems, which in my view is better than the standard grid where the look is inconsistent over different operating systems.
Best regards,
Richard

Hi
I'm not quite sure if You get exactly what problem I'm facing with.
I have already written and tested big application using WinForms. I'm extending it with RadGridView so to make it consistence either I have to change everything to telerik controls what for now is not an option or fit in RadGidView, so it will match WinForms.
I hope some of telerik core developers will read that post and extend it with WinForms look and feel.
Regards.

Yes, I think I understand your issue but as you have mentioned, the standard grid looks different on different operating systems. Any sort of theme won't do this unless you can develop a theme and then change it depending on the OS.
Best regards,
Richard

Hi
"the standard grid looks different on different operating systems" - all winforms does
"Any sort of theme won't do this unless you can develop a theme and then change it depending on the OS. " - that's why I raised this ticket, I'd like to have a help from Telerik Team in creating such a behavior. I need some theme that look exactly like WinForms on different OS.
Regards.
Thank you for your suggestions.
Presently, the theming system of Telerik Presentation Framework does not support that kind of scenario.
What you can do is create a theme that resembles the style of the Microsoft controls. Actually, you should create two themes - one for the style of the Microsoft controls that you get under Windows XP and one for the style of the controls under Windows 7. You can also use Windows7 theme that we provide for the latter case. Then, when you start your application, simply execute the following logic in your form:
if
(System.Environment.OSVersion.Version.Major >= 6)
{
ThemeResolutionService.ApplicationThemeName =
"Windows7"
;
}
else
{
ThemeResolutionService.ApplicationThemeName =
"CustomXPTheme"
;
}
I hope this helps.
Best wishes,
the Telerik team

Hi!
I have found in RadElement class method:
VisualStyleElement GetXPVisualStyle()
Can I somehow apply style returned by this method to my controls?
I was searching forum to find some information about this method but I didn`t find anything.
Regards

I was testing this method in my custom cell class but this method returns null.
Does this method work?
public
class
CellXP : GridDataCellElement
{
public
CellXP(GridViewColumn column, GridRowElement row)
:
base
(column, row)
{
}
}
public
class
ColumnXP : GridViewTextBoxColumn
{
public
override
Type GetCellType(GridViewRowInfo row)
{
if
(row
is
GridViewDataRowInfo)
{
return
typeof
(CellXP);
}
return
base
.GetCellType(row);
}
}
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Windows.Forms.VisualStyles;
namespace
GetXPVisualStyle
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
radGridView1.Columns.Add(
new
ColumnXP());
radGridView1.Columns.Add(
new
ColumnXP());
radGridView1.Rows.Add(
"0:0"
,
"0:1"
);
radGridView1.Rows.Add(
"1:0"
,
"1:1"
);
}
private
void
radGridView1_CellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
VisualStyleElement xpStyle = e.CellElement.GetXPVisualStyle();
//xpStyle is null, why?
}
}
}
Regards

The CellElement is near the end of a long inheritance chain. None of the items in that chain implement GetXPVisualStyles apart from the base RadElement which returns Null. This is different in the case of other elements.
Regards,
Richard
@Raymond: As Richard mentioned, non of the items in TPF implements this method. This method was a part of a feature which we did not introduced in favor of other important tasks. However, currently we do not plan to develop the feature further and we will hide the method in question.
@Richard: Thank you for your assistance in the forums.
Svett
the Telerik team

Hi!
Creating new theme is very time consuming so I tried another idea – just hook formatting events and change colors to required values.
Generally my goal is to have RadGridView that looks like standard ListView (according to OS settings).
I made simple example but not everything is updated according to my changes.
namespace
GetXPVisualStyle
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
FillTelerikGrid();
radGridView1.EnableAlternatingRowColor =
false
;
radGridView1.EnableHotTracking =
false
;
radGridView1.MultiSelect =
true
;
radGridView1.BackColor = Color.Green;
}
private
void
FillTelerikGrid()
{
List<HierarchicalClass> level1 =
new
List<HierarchicalClass>();
level1.Add(
new
HierarchicalClass() { Id =
"1"
, Name =
"row1, level1"
, ParentId =
string
.Empty });
level1.Add(
new
HierarchicalClass() { Id =
"2"
, Name =
"row2, level1"
, ParentId =
string
.Empty });
List<HierarchicalClass> level2 =
new
List<HierarchicalClass>();
level2.Add(
new
HierarchicalClass() { Id =
"3"
, Name =
"row1, level2"
, ParentId =
"1"
});
level2.Add(
new
HierarchicalClass() { Id =
"4"
, Name =
"row2, level2"
, ParentId =
"1"
});
level2.Add(
new
HierarchicalClass() { Id =
"5"
, Name =
"row3, level2"
, ParentId =
"2"
});
level2.Add(
new
HierarchicalClass() { Id =
"6"
, Name =
"row4, level2"
, ParentId =
"2"
});
List<HierarchicalClass> level3 =
new
List<HierarchicalClass>();
level3.Add(
new
HierarchicalClass() { Id =
"7"
, Name =
"row1, level3"
, ParentId =
"3"
});
level3.Add(
new
HierarchicalClass() { Id =
"8"
, Name =
"row2, level3"
, ParentId =
"3"
});
level3.Add(
new
HierarchicalClass() { Id =
"9"
, Name =
"row3, level3"
, ParentId =
"3"
});
this
.radGridView1.DataSource = level1;
GridViewTemplate templateLevel2 =
new
GridViewTemplate();
templateLevel2.DataSource = level2;
this
.radGridView1.Templates.Add(templateLevel2);
GridViewRelation relation12 =
new
GridViewRelation();
relation12.RelationName =
"relation12"
;
relation12.ParentTemplate =
this
.radGridView1.MasterTemplate;
relation12.ChildTemplate = templateLevel2;
relation12.ParentColumnNames.Add(
"Id"
);
relation12.ChildColumnNames.Add(
"ParentId"
);
this
.radGridView1.Relations.Add(relation12);
GridViewTemplate templateLevel3 =
new
GridViewTemplate();
templateLevel3.DataSource = level3;
templateLevel2.Templates.Add(templateLevel3);
GridViewRelation relation23 =
new
GridViewRelation();
relation23.RelationName =
"relation23"
;
relation23.ParentTemplate = templateLevel2;
relation23.ChildTemplate = templateLevel3;
relation23.ParentColumnNames.Add(
"Id"
);
relation23.ChildColumnNames.Add(
"ParentId"
);
this
.radGridView1.Relations.Add(relation23);
}
private
void
radGridView1_ViewCellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
e.CellElement.RowElement.HotTracking =
false
;
e.CellElement.ForeColor = Color.Red;
e.CellElement.BackColor = Color.Blue;
e.CellElement.BorderWidth = 0;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.HorizontalLineColor = Color.Blue;
}
private
void
radGridView1_ViewRowFormatting(
object
sender, RowFormattingEventArgs e)
{
e.RowElement.Font = listView1.Font;
e.RowElement.TableElement.RowHeight = 18;
e.RowElement.TableElement.TableHeaderHeight = 18;
e.RowElement.HotTracking =
false
;
e.RowElement.ForeColor = Color.Red;
e.RowElement.BackColor = Color.Blue;
e.RowElement.GradientStyle = GradientStyles.Solid;
e.RowElement.BorderWidth = 0;
e.RowElement.HorizontalLineColor = Color.Blue;
e.RowElement.GridBorderHorizontalColor = Color.Blue;
}
private
void
radGridView1_RowFormatting(
object
sender, RowFormattingEventArgs e)
{
e.RowElement.HotTracking =
false
;
e.RowElement.ForeColor = Color.Red;
e.RowElement.BackColor = Color.Blue;
e.RowElement.GradientStyle = GradientStyles.Solid;
}
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
e.CellElement.RowElement.HotTracking =
false
;
e.CellElement.ForeColor = Color.Red;
e.CellElement.BackColor = Color.Blue;
e.CellElement.BorderWidth = 0;
e.CellElement.GradientStyle = GradientStyles.Solid;
}
}
}
public
class
HierarchicalClass
{
public
string
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
string
ParentId {
get
;
set
; }
}
I have couple questions:
1. What is the difference between ViewCellFormatting event and CellFormatting?
I don`t see difference but if there are two kinds of these events probably there is something…
The same question I have about row formatting events (view and without view).
2. I cannot disable hot tracking on rows that are not root rows. For root rows hot tracking is disabled. How to disable hot tracking for all rows?
3. When I run my app it looks that RadGridView doesn`t apply all my changes.
Problem is that the first row has blue background only in first cell and second row is not blue at all. Why? I haven’t added condition to change background only for selected rows yet but I don`t need this logic at this moment.
4. Next problem is that when I select first row still not all area of row becomes blue. Selected cell is ok but other cells from this row have yellow/orange horizontal lines (on the top and bottom of the row). How to make whole row area blue?
5. How can I remove grid lines? For example standard list view doesn`t have these lines.
BTW: why I cannot attach any screenshots?
Regards

I'll answer the questions that I can answer. Some I may have to come back to you on.
1: the difference between CellFormatting and ViewCellFormatting is while CellFormatting event is fired only for data cells, ViewCellFormatting is fired for all RadGridView cells. So if you want to format the grouping row or the header cells, you should use ViewCellFormatting. Have a look at the documentation here
For the other items, have a look over the dicumentation as above. you are handling both the CellFormatting and ViewCellFormatting events for exmaple and not resetting the LightVisualElement.
5: You can remove all grid lines by not drawing the border. For example
private
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
e.CellElement.DrawBorder =
false
;
}
Re: Adding images, there is a current issue with the site which is due to be fixed on the next web maintenance update.
hope this helps
Richard
Please check the answers that Richard suggested, all they are correct. Regarding the rest of your questions - please check the comments in the following code snippet. I have skipped the FillTelerikGrid method and the HierarchicalClass for better readability:
public
Form1()
{
InitializeComponent();
FillTelerikGrid();
radGridView1.EnableAlternatingRowColor =
false
;
radGridView1.EnableHotTracking =
false
;
radGridView1.MultiSelect =
true
;
radGridView1.BackColor = Color.Green;
radGridView1.ViewCellFormatting+=
new
CellFormattingEventHandler(radGridView1_ViewCellFormatting);
radGridView1.ViewRowFormatting+=
new
RowFormattingEventHandler(radGridView1_ViewRowFormatting);
}
private
void
radGridView1_ViewCellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
//allow changing the colors
e.CellElement.DrawFill =
true
;
//make the styling
if
(e.CellElement
is
GridDataCellElement)
{
e.CellElement.ForeColor = Color.Red;
e.CellElement.BackColor = Color.Blue;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.HorizontalLineColor = Color.Blue;
e.CellElement.Font = listView1.Font;
e.CellElement.BorderWidth = 0;
}
//reset those settings for NON-data cells
else
{
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty);
e.CellElement.ResetValue(LightVisualElement.HorizontalLineColorProperty);
e.CellElement.ResetValue(LightVisualElement.FontProperty);
e.CellElement.ResetValue(LightVisualElement.BorderWidthProperty);
}
//hide the borders
e.CellElement.DrawBorder =
false
;
//stop the hot tracking for child views
if
(e.CellElement
is
GridDetailViewCellElement)
{
GridDetailViewCellElement cell = e.CellElement
as
GridDetailViewCellElement;
cell.ChildTableElement.EnableHotTracking =
false
;
}
}
private
void
radGridView1_ViewRowFormatting(
object
sender, RowFormattingEventArgs e)
{
//here resetting is not needed in case you want those setting to be applied to all rows (header, filter, grouping etc)
e.RowElement.TableElement.RowHeight = 18;
e.RowElement.TableElement.TableHeaderHeight = 18;
}
I hope this information addresses your question. If something is not clear of you need further assistance, do not hesitate to write back.
Richard, thank you for the community effort. Your Telerik Points have been upgraded for this.
All the best,
Stefan
the Telerik team

Thanks for explanations – it was helpful for me.
Tomorrow I will test proposal from Admin.
Regards

Please help out!
private
void m_radGridViewFunction_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
e.CellElement.DrawBorder = false;
e.CellElement.BorderColor = Color.Transparent;
e.CellElement.BorderWidth = 0;
e.CellElement.HorizontalLineColor = Color.Transparent;
e.CellElement.HorizontalLineWidth = 0;
}

Please take a look at this article on how to make a RadGridView as a multicolumnlistbox
Hope that helps
Richard

private
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
e.CellElement.DrawFill = true;
e.CellElement.DrawBorder = false;
e.CellElement.GradientStyle = GradientStyles.Solid;
}
But then, the rows are getting multiselected for which I have changed as, (i did not want multiselection as in RadListBox).
private
void m_radGridViewFunction_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
if (e.CurrentRow != null)
e.CurrentRow.Cells[0].CellElement.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(252)))), ((int)(((byte)(154)))), ((int)(((byte)(63)))));
if (e.OldRow != null)
e.OldRow.Cells[0].CellElement.BackColor = Color.White;
}
Still this does not work completely as when i scroll with the scroll bar of grid view, the items get selected . When i scroll top, top element gets selected. When I scroll down, bottom element gets selected and so on .
Can you please let me know the event fired when scroll bar is moved up & down? Scroll event is not called.