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

change grid cell color after checkbox click

4 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Carisch
Top achievements
Rank 1
Carisch asked on 06 Jul 2011, 08:50 PM
I'm having difficulty understanding the flow of how these events get called and where I should modify formatting info. 

The grid view events I'm working with currently are grid_CellFormatting, grid_CellBeginEdit, grid_CellEndEdit.  I have a grid, that has many columns of data that are bound to a generic list of objects.  These objects have bool properties I'd like to allow the user to update through a single grid with many columns/rows.  The majority of the columns are GridViewCheckBoxColumn(the ones that I want to not be read-only).  I'd like to allow the user to check these boxes, and it will turn the cell they are contained within to a different color.  Then after they've clicked many, they can commit these changes using a save button.  

I assume that I can only update the formatting of a cell in the _cellformatting event.  So, I assume I need to pass some data along to this event that allows it to look at the checkbox and determine if the value is changed.  I've written some code that would do this using the .Tag object on the cell.  This isn't working well, and I'm looking for some advise.  I can't be the first one to use a grid in this fashion.  Allow users to make changes, and see those changes, and then commit all at once.

Any advice?

4 Answers, 1 is accepted

Sort by
0
Carisch
Top achievements
Rank 1
answered on 06 Jul 2011, 10:29 PM
Well finding the demo app > GridView > Customize > formatting with code, several hours ago would have helped.   For me, the .DrawFill property is what I needed to make everything function.  For whatever reason I can't call e.CellElement.Tag directly, I have to go throught the e.Row syntax.  That certainly wasn't obvious.

Since this is a checkbox, if I begin edit, I set the tag to true if wasn't already true.  Basically first time you click, it's a new value and needs to be saved, second its setting it back to what it was when loaded.
private void gridProducts_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (e.Row.Cells[e.ColumnIndex].Tag == null)
        e.Row.Cells[e.ColumnIndex].Tag = true;
    else
        e.Row.Cells[e.ColumnIndex].Tag = null;
}

private void gridProducts_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Row.Cells[e.ColumnIndex].Tag != null)
    {
        e.CellElement.DrawFill = true;
        e.CellElement.BackColor = Color.Pink;
    }
    else
    {
        e.CellElement.DrawFill = true;
        e.CellElement.BackColor = Color.Transparent;
    }
}

0
Jack
Telerik team
answered on 10 Jul 2011, 12:33 PM
Hi Carisch, I am glad to hear that you have found a solution for this issue. Please, do not hesitate to contact us if you have any other questions.
 
All the best,
Jack
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Sajitha
Top achievements
Rank 1
Veteran
answered on 17 Mar 2021, 04:48 PM

Dear Team,

I have a kendo grid which displays a number of checkboxes to give and remove permission to the users. Now I have implemented a new flow, in which the new requests ( the newly clicked checkboxes) whould go thru an approval process. My current requirement is to give a specific color to the newly checked checkboxes which are pending for approval. I have set some pending flags and when I implemented the below code, the entire row gets colored. I do not want the entire row to change the color. Can you please let me know, how to change the color of the individual cell / specific cell based on condition.

if (dataItem.get("PendingAdmin"))

{                   
            row.find(".k-checkbox:visible").attr("style", "color: greenyellow !important");
}

Please suggest a solution?

 

Thanks,

Sajitha

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Mar 2021, 05:24 AM

Hi, Sajitha,

I would like to note that this forum is related to the Telerik UI for WinForms product. However, your question seems to be related to the Kendo Grid.

Feel free to post any inquiries that you have in the relevant forum and thus the appropriate community will assist you: https://www.telerik.com/forums 

Thank you for your understanding.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Carisch
Top achievements
Rank 1
Answers by
Carisch
Top achievements
Rank 1
Jack
Telerik team
Sajitha
Top achievements
Rank 1
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or