- How do I force the highlighting to take effect on the entire row?
- How do I allow someone to hold down the Control button and "deselect" that row, thus removing the highlighting?
Basically what I'm looking for is a way to simply display the data, and when they click on the row, I'll use a handle to determine the row ID to use to edit the row using another window. The data is far too complicated to edit directly in a grid.
Thanks in advance!
14 Answers, 1 is accepted
To change the appearance of the current cell and row you should subscribe to CellFormatting event of RadGridView and do the following:
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.RowInfo.IsCurrent)
{
if
(e.CellElement.IsCurrent)
{
e.CellElement.GradientStyle = GradientStyles.Solid;
}
e.CellElement.RowInfo.VisualElement.GradientStyle = GradientStyles.Solid;
e.CellElement.RowInfo.VisualElement.BackColor = e.CellElement.BackColor;
}
else
{
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.RowInfo.VisualElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.CellElement.RowInfo.VisualElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
}
}
Regarding changing the selection when the user holds the Ctrl button, you may subscribe to KeyUp and KeyDown events of the grid:
private
GridViewRowInfo currentRow;
private
bool
isControlDown =
false
;
private
void
radGridView1_KeyUp(
object
sender, KeyEventArgs e)
{
if
(
this
.isControlDown)
{
this
.radGridView1.CurrentRow =
this
.currentRow;
this
.isControlDown =
false
;
this
.currentRow =
null
;
}
}
private
void
radGridView1_KeyDown(
object
sender, KeyEventArgs e)
{
if
(e.Modifiers == Keys.Control && !
this
.isControlDown)
{
this
.isControlDown =
true
;
this
.currentRow =
this
.radGridView1.CurrentRow;
this
.radGridView1.CurrentRow =
null
;
}
}
If you need further assistance, feel free to ask us.
Kind regards,
Svett
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
In most applications that have a multi-selection box, you can highlight one or more line items, typically by clicking on them via the mouse. If you want to select more than one, you hold down the Control button while selecting the individual ones, or if you hold down Shift and click a second line item, everything between the last line item that was clicked and the one you just clicked on will be highlighted.
But if you want to "deselect" something from the list of selected line items, you hold down the Control button while clicking on the item that you wish to deselect. How do I achieve that type of functionality?
We are happy that you resolved it on your own. Additionally, our knowledge base and documentation articles can be very helpful in most cases.
Let me know, if you need further assistance.
All the best,
Svett
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I am using RagGridView control to display elements of the data in my application.
I have selected Selectionmode = FullRowSelect,
and Multiselect = True.
I am using control key and mouse to select multiple records, and after that deselecting one of the record from the list of selected records again using control key.
In actual that record gets deselected but it is showing highlighted.
I want that record should not be highlighetd when that is deselected.I used KeyUp and KeyDown events(As per suggetion in one of the telerik support link) to solve this but it is not working yet.
I am not able to reproduce the issue by following the supplied information in the latest version Q2 2011 SP1 (2011.2 11.831). I would kindly ask you to open a support ticket where you can attach a sample project where the issue occurs. In addition, could you give us more details regarding the steps that we should follow to reproduce it? Thank you for your cooperation.
Best wishes,Svett
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.
As in, how do I not show the selected cell but only the selected row?
Thank you,
You can change the visual appearance by using the CellFormatting event. You can read more about it in the online documentation. In your case, you should use the following code snippet:
private
void
radGridView1_CellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if
(e.Column.IsCurrent && e.Column.IsCurrent)
{
e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
e.CellElement.BorderLeftColor = Color.FromArgb(255, 209, 225, 245);
e.CellElement.BorderRightColor = Color.FromArgb(255, 209, 225, 245);
e.CellElement.BorderTopColor = Color.FromArgb(255, 255, 190, 106);
e.CellElement.BorderBottomColor = Color.FromArgb(255, 255, 190, 106);
e.CellElement.BorderLeftShadowColor = Color.Transparent;
e.CellElement.BorderRightShadowColor = Color.Transparent;
e.CellElement.BorderTopShadowColor = Color.FromArgb(255, 255, 245, 162);
e.CellElement.BorderBottomShadowColor = Color.FromArgb(255, 255, 245, 162);
}
else
{
e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderLeftShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderRightShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomShadowColorProperty, ValueResetFlags.Local);
}
}
I hope this helps.
Greetings,Svett
the Telerik team
Thank you very much, that does work, except that I'm using the office 2010 Blue theme and it doesn't look quite right.
Is there somewhere that I can look to see what color values I should be using for the various border parameters?
...or better yet, is there any way to dynamically query the style of a non-selected cell right in the code, for my theme, and apply that style in the event?
Regards,
There is no way to query the non-selected cell style and apply it to the selected one. You should have a different approach for each theme. You can use the following implementation of CellFormatting event handler for Office 2010 Blue Theme:
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.Column.IsCurrent && e.Column.IsCurrent)
{
e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
e.CellElement.BorderLeftColor = Color.FromArgb(255, 206, 223, 242);
e.CellElement.BorderRightColor = Color.FromArgb(255, 206, 223, 242);
e.CellElement.BorderTopColor = Color.FromArgb(255, 211, 132, 56);
e.CellElement.BorderBottomColor = Color.FromArgb(255, 211, 132, 56);
e.CellElement.BorderRightWidth = 1;
e.CellElement.BorderLeftWidth = 1;
e.CellElement.BorderTopWidth = 1;
e.CellElement.BorderBottomWidth = 1;
e.CellElement.BorderLeftShadowColor = Color.Transparent;
e.CellElement.BorderRightShadowColor = Color.Transparent;
e.CellElement.BorderTopShadowColor = Color.Transparent;
e.CellElement.BorderBottomShadowColor = Color.Transparent;
}
else
{
e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderLeftShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderRightShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomShadowColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopWidthProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomWidthProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderRightWidthProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderLeftWidthProperty, ValueResetFlags.Local);
}
}
I hope this helps.
Greetings,Svett
the Telerik team
I just had to make a small correction to your code:
If
e.Row.IsCurrent
AndAlso
e.Column.IsCurrent
Then
e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders
e.CellElement.BorderLeftColor = System.Drawing.Color.FromArgb(255, 206, 223, 242)
e.CellElement.BorderRightColor = System.Drawing.Color.FromArgb(255, 206, 223, 242)
e.CellElement.BorderTopColor = System.Drawing.Color.FromArgb(255, 211, 132, 56)
e.CellElement.BorderBottomColor = System.Drawing.Color.FromArgb(255, 211, 132, 56)
e.CellElement.BorderRightWidth = 1
e.CellElement.BorderLeftWidth = 1
e.CellElement.BorderTopWidth = 1
e.CellElement.BorderBottomWidth = 1
e.CellElement.BorderLeftShadowColor = System.Drawing.Color.Transparent
e.CellElement.BorderRightShadowColor = System.Drawing.Color.Transparent
e.CellElement.BorderTopShadowColor = System.Drawing.Color.Transparent
e.CellElement.BorderBottomShadowColor = System.Drawing.Color.Transparent
Else
e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderTopColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderBottomColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderLeftShadowColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderRightShadowColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderTopShadowColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderBottomShadowColorProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderTopWidthProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderBottomWidthProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderRightWidthProperty, ValueResetFlags.Local)
e.CellElement.ResetValue(LightVisualElement.BorderLeftWidthProperty, ValueResetFlags.Local)
End
If
In particular,
e.Row.IsCurrent
AndAlso
e.Column.IsCurrent.
Thanks,
I am using RagGridView control to display elements of the data in my application.
I have selected Selectionmode = FullRowSelect,
and Multiselect = True.
Regarding selection we have below 2 queries.
1. As i have posted earlier - I am selecting record in gridview with mouseclick and again using ctrl key + mouse click on the same record..
In application it remain highlighted as selected(actaul it is not selected) but if dubbuging the code actual selected records in grid are 0.
To solve this problem currently i am saving currentrow information which was selected first with mouseclick and when same record click with ctrl + mouseclick assiging that saved row to RagGridView.currentRow so at the end it will have actual record selected to 1 instead of 0.
do you suggest any other solution for this deselection because our requirement is gridveiw shoudl have atleast one record selected.
2. when we select multiple(eg. 4 records) records with shift key + mouse and on one of these selected rows we are using ctrl key +mouseclick.
Then what happen is 4 records showing highlighted but when degugged found Gridview has selected records 3 instead of 4.
when we are selecting multiple records we are showing some analysis on those selected records but due above case actaul it show analysis of 3 records and grid shows 4 records highlighted which means selected which is very confusing,
Both should match.
Can you suggest some solution for this problem.
I did not manage to reproduce the issues that you are experiencing with Q1 2012 (2012.2 12.608). Could you open a support ticket where you can enclose a sample project which demonstrates your scenario in first hand? Also could you illustrate the exact steps that we should follow?
Regards,
Svett
the Telerik team