7 Answers, 1 is accepted
0
Hi Miki,
Thank you for writing.
This is possible and to achieve it you should create a custom cell element:
The default cell can be changed like this:
Additionally, you should create custom header row behavior and override the OnMouseDown method. This is necessary because by default the header cell click sorts the grid:
You can change the default behavior with the following code:
Please let me know if there is something else I can help you with.
Regards,
Dimitar
Telerik
Thank you for writing.
This is possible and to achieve it you should create a custom cell element:
class
MyGridHeaderCellElement : GridHeaderCellElement
{
public
MyGridHeaderCellElement(GridViewColumn col, GridRowElement row) :
base
(col,row)
{
}
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
RadSpinElement element =
new
RadSpinElement();
element.StretchVertically =
false
;
this
.Children.Add(element);
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridHeaderCellElement);
}
}
}
The default cell can be changed like this:
void
radGridView1_CreateCell(
object
sender, Telerik.WinControls.UI.GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridHeaderCellElement))
{
e.CellElement =
new
MyGridHeaderCellElement(e.Column,e.Row);
}
}
Additionally, you should create custom header row behavior and override the OnMouseDown method. This is necessary because by default the header cell click sorts the grid:
class
MyGridHeaderRowBehavior : GridHeaderRowBehavior
{
public
override
bool
OnMouseDown(MouseEventArgs e)
{
MyGridHeaderCellElement element =
this
.GridControl.ElementTree.GetElementAtPoint(e.Location)
as
MyGridHeaderCellElement;
if
(element !=
null
)
{
return
base
.OnMouseDown(e);
}
return
true
;
}
}
You can change the default behavior with the following code:
BaseGridBehavior gridBehavior = radGridView1.GridBehavior
as
BaseGridBehavior;
gridBehavior.UnregisterBehavior(
typeof
(GridViewTableHeaderRowInfo));
gridBehavior.RegisterBehavior(
typeof
(GridViewTableHeaderRowInfo),
new
MyGridHeaderRowBehavior());
Please let me know if there is something else I can help you with.
Dimitar
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
miki
Top achievements
Rank 1
answered on 21 Jan 2015, 10:17 AM
The Spineditor that i want to add is inside my column header called Speed, so i change the radGridView1_CreateCell into this:
And now i can see the Spineditor only inside this column header.
1. How can i see the header name "Speed" beside the Spineditor ?
2. How can i set minimum and maximum values into my Spineditor ?
3. when i change the Spineditor value how can i catch this evnt in order to change my GridView objects accordingly ?
private
void
radGridView1_CreateCell(
object
sender, GridViewCreateCellEventArgs e)
{
if
(e.Column.HeaderText ==
"Speed"
&& e.CellType ==
typeof
(GridHeaderCellElement))
{
e.CellElement =
new
MyGridHeaderCellElement(e.Column, e.Row);
}
}
And now i can see the Spineditor only inside this column header.
1. How can i see the header name "Speed" beside the Spineditor ?
2. How can i set minimum and maximum values into my Spineditor ?
3. when i change the Spineditor value how can i catch this evnt in order to change my GridView objects accordingly ?
0
miki
Top achievements
Rank 1
answered on 21 Jan 2015, 10:40 AM
This is my update for question number 3:
I try to catch the Speneditor event inside Cell Click event:
Now how can i catch the Spineditor value after changed ?
I try to catch the Speneditor event inside Cell Click event:
private
void
radGridView1_CellClick(
object
sender, GridViewCellEventArgs e)
{
string
cellName = e.Column.HeaderText;
if
(e.RowIndex == -1 && cellName ==
"Speed"
)
{
}
}
0
Hi Miki,
Thank you for writing back.
1. You need to set the StretchHorizontally, Alignment and FitToSizeMode properties of the spin element.
2. You can use the MinValue and MaxValue properties of the spin element.
3. The CellClick event is not suitable for this case. You should use the ValueChanged event of the spin element. You can subscribe to this event in the MyGridHeaderCellElement class, you can access the grid there as well.
I have attached a small sample to show you how this can be implemented.
Do not hesitate to contact us if you have other questions.
Regards,
Dimitar
Telerik
Thank you for writing back.
1. You need to set the StretchHorizontally, Alignment and FitToSizeMode properties of the spin element.
2. You can use the MinValue and MaxValue properties of the spin element.
3. The CellClick event is not suitable for this case. You should use the ValueChanged event of the spin element. You can subscribe to this event in the MyGridHeaderCellElement class, you can access the grid there as well.
I have attached a small sample to show you how this can be implemented.
Do not hesitate to contact us if you have other questions.
Dimitar
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
miki
Top achievements
Rank 1
answered on 24 Jan 2015, 08:30 PM
Hi,
When i am using your solution with a custom cell element i notice a strange behavior:
Every time I try to reduce or expand cell header, even if i didn't release the left mouse button this cell automatically expanded and i cannot reduce it's size, the minimum size i can reduce is the original size, this cause in every cell header and this behavior was not previously.
When i am using your solution with a custom cell element i notice a strange behavior:
Every time I try to reduce or expand cell header, even if i didn't release the left mouse button this cell automatically expanded and i cannot reduce it's size, the minimum size i can reduce is the original size, this cause in every cell header and this behavior was not previously.
0
Hello Miki,
Thank you for writing back.
This issue comes from the custom implementation in the OnMouseDown method. In this case I have not considered that this method will be triggered when the cells are resized. Nevertheless you can use the following implementation and this would not occur:
Hope I could help.
Regards,
Dimitar
Telerik
Thank you for writing back.
This issue comes from the custom implementation in the OnMouseDown method. In this case I have not considered that this method will be triggered when the cells are resized. Nevertheless you can use the following implementation and this would not occur:
class
MyGridHeaderRowBehavior : GridHeaderRowBehavior
{
public
override
bool
OnMouseDown(MouseEventArgs e)
{
RadElement element =
this
.GridControl.ElementTree.GetElementAtPoint(e.Location);
if
(element !=
null
&& element.FindAncestor<RadSpinElement>() !=
null
)
{
return
true
;
}
return
base
.OnMouseDown(e);
}
}
Hope I could help.
Dimitar
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
miki
Top achievements
Rank 1
answered on 29 Jan 2015, 06:13 PM
That's work perfect !
Thanks a lot for your help.
Thanks a lot for your help.