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

Changing cell value causes a blank cell

1 Answer 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 04 Mar 2014, 03:58 AM
I'm writing an application which iterates through the rows of an unbound RadGridView and changes the value and formatting of a particular cell as it goes.  I'm having no issue iterating through the rows, but when I get to the point of calling for a cell's value or formatting to change the cell empties of all visible data instead.

The way I'm iterating through the cells and changing the value is like so:

foreach (GridViewRowInfo row In rgvFiles.Rows)
{
    row.Cells[2].Value = "New Text";
    row.Cells[2].Style.BackColor = Color.DarkGreen;
    row.Cells[2].Style.ForeColor = Color.White;
}

1 Answer, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 05 Mar 2014, 04:19 PM
Hi Adrian, 

Thank you for contacting Telerik Support. 

In your code you set the ForeColor of cell to White while at the same time the BackColor of the cell is White as well, hence you cannot see the text because you have white on white. 

If you want to change the BackColor property of the cell using the Style property, you need to set the CustomizeFill property to true. Please take a look at the following code example:
foreach (GridViewRowInfo row in this.radGridView1.Rows)
{
    row.Cells["TextBoxColumn"].Value = "New Text";
    row.Cells["TextBoxColumn"].Style.CustomizeFill = true;
    row.Cells["TextBoxColumn"].Style.BackColor = Color.DarkGreen;
    row.Cells["TextBoxColumn"].Style.ForeColor = Color.White;
}

Another approach to style the cells in RadGridView is to use its formatting events. More information about this functionality is available here: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.

Hope this will help you. Let me know if you have any other questions.

Regards,
Ralitsa
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Tags
GridView
Asked by
Adrian
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Share this question
or