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

Disable cell highlighting/row-only selection

14 Answers 575 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mtaber
Top achievements
Rank 1
mtaber asked on 30 Dec 2009, 03:57 AM
I'd like to be able to use the GridView control to display elements of the data using the HtmlViewDefinition. I have three cells, one of which is on the first "line", and the other two are below it. When I display the data in the Grid, if I click on a "cell", it is highlighted in one color(orange), while the row itself is highlighted in another(light yellow). If I select another column, it goes to light yellow.

  1. How do I force the highlighting to take effect on the entire row?
  2. 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

Sort by
0
Accepted
Svett
Telerik team
answered on 30 Dec 2009, 10:19 AM
Hello mtaber,

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.
0
mtaber
Top achievements
Rank 1
answered on 31 Dec 2009, 02:15 AM
I got #1 working, but #2 is still giving me trouble. Looks like I explained what I was looking for incorrectly.

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?
0
Accepted
Robert
Top achievements
Rank 1
answered on 31 Dec 2009, 05:21 PM
Hello mtaber,

You should be able to achieve the functionality you have described pretty easily. I wrote a quick test application using the RadGridView and populated it with some custom data. In the property builder for the RadGridView, I set the Selection Mode to FullRowSelect, and I set the Multi Select check box to true. On the GridViewTemplate, I set AllowAddNewRow to false, AllowDeleteRow to false, and AllowEditRow to false.

Once my application is up and running I can do the following things:
Click an item to select it. Click shift to select all items listed between the first item selected and the item just clicked.
Hold down the control key and click items to select them.
Hold down the control key and click selected items to deselect them.

This seems to be out-of-the-box behavior for me. What exactly is happening when you ctrl-click unselected/selected items?

- Robert
0
mtaber
Top achievements
Rank 1
answered on 31 Dec 2009, 05:59 PM
Thanks!! Looks like it was the Multi-select option that I didn't have set properly. I was sure I'd set that, but apparently not. That's my fault. Thanks for your help.
0
Svett
Telerik team
answered on 04 Jan 2010, 09:13 AM
Hi mtaber,

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.
0
Nitesh
Top achievements
Rank 1
answered on 12 Nov 2011, 01:04 PM
Hi
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.
0
Svett
Telerik team
answered on 15 Nov 2011, 09:32 AM
Hello Nitesh,

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.

0
Alex
Top achievements
Rank 1
answered on 21 Mar 2012, 07:33 AM
How do you do this with the latest version?

As in, how do I not show the selected cell but only the selected row?

Thank you,
0
Svett
Telerik team
answered on 23 Mar 2012, 05:18 PM
Hi Alex,

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
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Alex
Top achievements
Rank 1
answered on 23 Mar 2012, 07:38 PM
Svett,

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,
0
Accepted
Svett
Telerik team
answered on 27 Mar 2012, 03:45 PM
Hi Alex,

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
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Accepted
Alex
Top achievements
Rank 1
answered on 12 Apr 2012, 10:25 PM
Yes, thank you.

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,
0
Nitesh
Top achievements
Rank 1
answered on 18 Jul 2012, 06:10 AM
Hi
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.
0
Svett
Telerik team
answered on 20 Jul 2012, 09:57 AM
Hello Nitesh,

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
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
mtaber
Top achievements
Rank 1
Answers by
Svett
Telerik team
mtaber
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Nitesh
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Share this question
or