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

Cell focus/highlight

15 Answers 324 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Svein Thomas
Top achievements
Rank 1
Svein Thomas asked on 18 Feb 2011, 04:01 PM
Hi,

My grid is a readonly grid and with FullRow Selection mode. But still are the cells highlighted when i'm clicking in the grid. Look at the attached screenshot.

How can I disable this highlighting ? 

I have tried with this code, but still the cell is "in a way" highlighted..

if (e.CellElement.IsCurrent)
            {
                e.CellElement.DrawFill = false;
                e.CellElement.DrawBorder = false;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
            }

BTW: The EnableHotTracking is truned of.

Regards
Svein Thomas

15 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 18 Feb 2011, 05:24 PM
Hello,

If you are calling this code from the CellFormatting event, then the result should be as per the attached screenshot. Even though it doesn't draw the border, you can still see that it is the current cell (slightly) as there are some other properties that are different (BorderBoxStyle, Shadows etc).

From the look of it, your event is not being called. Ensure you have set up the event handler as shown
this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement.IsCurrent)
    {
        e.CellElement.DrawFill = false;
        e.CellElement.DrawBorder = false;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

hope that helps
Richard
0
Svein Thomas
Top achievements
Rank 1
answered on 18 Feb 2011, 09:44 PM
Hi Richard,

The picture is not with the event attached, that is correct.
But even when i do attach this event, i still can see a difference in the cell content when clicking the cell. The texts in the cell moves a bit... please try it and you see what i mean...

Svein Thomas
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 19 Feb 2011, 02:11 AM
Hello,

As mentioned in my previous post, if you want it to truly look alike, then there are a few more properties to set. It looks as though you are using the Default theme, so I can give you the settings for those, though it could also be done of course by definin gyour own theme using the Visual stle Builder.

The non selected cells, still have a border, but are defined as this..
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement.IsCurrent)
    {
        e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
        e.CellElement.BorderTopColor = Color.FromArgb(255, 190, 106);
        e.CellElement.BorderTopShadowColor = Color.FromArgb(255, 245, 162);
        e.CellElement.BorderBottomColor = Color.FromArgb(255, 190, 106);
        e.CellElement.BorderBottomShadowColor = Color.FromArgb(255, 245, 162);
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderTopColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderTopShadowColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderBottomColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderBottomShadowColorProperty, Telerik.WinControls.ValueResetFlags.Local);
    }

Hope that helps but let me know if you have further questions
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 21 Feb 2011, 10:06 AM
Hello,

Did this help? If so, please remember to mark as answer. If you need further help, just let me know.
Thanks
Richard
0
Svein Thomas
Top achievements
Rank 1
answered on 21 Feb 2011, 11:28 AM
Why do we need to write this much code just to turn of the cell focus. This should be in the properties of the grid. Some different cellfocusing options. But yes, it worked :) Thanks for your help!

Regards
Svein Thomas
0
Richard Slade
Top achievements
Rank 2
answered on 21 Feb 2011, 11:39 AM
Hi,

Glad that helped. The cell borders are still there on the other cells, but they are just styled differently under the default theme. In this case we are just changing the style of the border to equal the other cells. You can of course though define your own theme so all cells on a selected row would remain the same.
Let me know if you have any other questions
Richard
0
Svein Thomas
Top achievements
Rank 1
answered on 21 Feb 2011, 06:53 PM
Hi again,

I would be happy if you would guide me on how to change the theme to do this. I already have a customized theme, and i tried to figure out where to set this settings with no luck.

Regards
Svein Thomas
0
Richard Slade
Top achievements
Rank 2
answered on 21 Feb 2011, 08:44 PM
Hello,

To be very honest, VSB is an area that is weaker in my knowledge. I must get to know it better. 

I have attaached a screenshot of the area that I beleive that you would have to change and the properties that you would need to change are the ones that are detailed in my previous reply.

I hope this helps, but if you think I might be able to assist you further, do just let me know.
Richard

edit// attaching image
0
Svett
Telerik team
answered on 24 Feb 2011, 02:07 PM
Hi Svein,

I suggest that you go through the ControlDefault theme and see how the cell styles are applied in all states. Then you should be able to delete these states (or unassociate respective repositories) in your theme. You can read the online documentation regarding the process of opening a predefined theme. In addition, you can read how to use Visual Style Builder here.

Kind regards,
Svett
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Accepted
David
Top achievements
Rank 1
answered on 22 Mar 2011, 06:37 PM
I was trying to do the exact same thing today, and I got it to work like this.  It worked wonderfully and without having to set explicit colors, etc. 

void LiquidRadGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement != null)
    {
        if (e.CellElement.IsCurrent)
        {
            e.CellElement.IsCurrent = false;
            e.CellElement.IsCurrentColumn = false;
        } else
        {
            e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        }
    }
}
0
Abdul
Top achievements
Rank 1
answered on 03 Jun 2017, 03:12 AM

Hi,

I have an issue that when a form(I have attached the screenshot) is loaded from another form and focus goes to a particular cell in RadGridView it does not selected(Highlighted with blue color).So that when i want to change the text,i simply do double left mouse click on the cell.Here i want to avoid mouse click,and do it programmatically select the text on the cell.Here is the code snippet:

private void frmProductSelect_Load(object sender, EventArgs e)
        {
            dgvProductSelect.Focus();
            dgvProductSelect.CurrentRow = dgvProductSelect.Rows[0];
            dgvProductSelect.CurrentColumn = dgvProductSelect.Columns["Quantity"];
            dgvProductSelect.Rows[0].Cells["Quantity"].Value = Convert.ToDecimal(rlbl_SalesQty.Text);
            dgvProductSelect.Rows[0].Cells["Quantity"].BeginEdit();
}

I think you got my problem.If you want any clarification,please let me know.

Regards

ABDUL HAFEEL

0
Hristo
Telerik team
answered on 05 Jun 2017, 02:43 PM
Hi Abdul,

Thank you for writing.

If I understand correctly, you would like to start editing the cell as soon as your form loads. The cell`s text will be selected by default. However, please consider setting the current row and column in the Shown event of your form: 
protected override void OnShown(EventArgs e)
{
    base.OnShown(e);
 
    this.radGridView1.CurrentRow = this.radGridView1.Rows[0];
    this.radGridView1.CurrentColumn = this.radGridView1.Columns[1];
 
    this.radGridView1.BeginEdit();
}

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abdul
Top achievements
Rank 1
answered on 06 Jun 2017, 03:05 AM

Thank You Hristo :) .It works correctly.

Regards

ABDUL HAFEEL

0
Abdul
Top achievements
Rank 1
answered on 23 Jun 2017, 04:19 AM

Hi ,

I need to implement the row move up and down in RadGridView using RadButtons in WinForms.

Regards
ABDUL HAFEEL

0
Hristo
Telerik team
answered on 23 Jun 2017, 12:06 PM
Hi Abdul,

Thank you for writing back.

I would like to first point that we try to keep our threads focused on a single topic. In the future please consider posting your other questions separately.

As to your actual question you can use the IsSelected and IsCurrent properties to select the next or previous rows: http://docs.telerik.com/devtools/winforms/gridview/rows/selected-rows-and-current-row.

If you need to move the entire row up or down you can use my code snippet below: 
private void btnDown_Click(object sender, EventArgs e)
{
    this.MoveRow(true);
}
 
private void btnUp_Click(object sender, EventArgs e)
{
    this.MoveRow(false);
}
 
private void MoveRow(bool forward)
{
    BaseGridNavigator navigator = this.radGridView1.GridNavigator as BaseGridNavigator;
    var oldCurrent = this.radGridView1.CurrentRow;
    if (forward)
    {
        navigator.SelectNextRow(1);
    }
    else
    {
        navigator.SelectPreviousRow(1);
    }
     
    var newCurrent = this.radGridView1.CurrentRow;
 
    if (newCurrent != null && newCurrent.Index > -1)
    {
        for (int i = 0; i < oldCurrent.Cells.Count; i++)
        {
            object oldValue = oldCurrent.Cells[i].Value;
            object newValue = newCurrent.Cells[i].Value;
            newCurrent.Cells[i].Value = oldValue;
            oldCurrent.Cells[i].Value = newValue;
        }
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Svein Thomas
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Svein Thomas
Top achievements
Rank 1
Svett
Telerik team
David
Top achievements
Rank 1
Abdul
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or