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

When is VisualElement set for GridViewRowInfo

3 Answers 164 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 04 Feb 2009, 06:36 PM
I'm currently using the grid.Rows.Add() method to add a new row when a particular event fires inside my application.

This works fine.

However, I am now trying to set the ForeColor of the row after I add it, but the VisualElement property is null, in the following code sample:
int rowIdx = traysGrid.Rows.Add( 
                        tray.TrayID, tray.Barcode, 
                        dataContext.Locations.Where(loc => loc.LocationID == trayHistory.LocationID).First().Name 
                        , 
                        trayHistory.ArrivalDate, 
                        AuthenticationController.GetLoggedInUserName(), 
                        tray.Notes 
                        ); 
GridViewDataRowInfo row = traysGrid.Rows[rowIdx]; 
 
traysGrid.GridElement.BeginUpdate(); 
row.VisualElement.BackColor = Color.Green; 
traysGrid.GridElement.EndUpdate(); 
 

I have used this method successfully when inside a foreach loop, but using it doesn't seem to work as above.

Any advice or ideas?

Thanks

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 05 Feb 2009, 01:27 PM
Hi Christopher,

Thank you for this question.

RadGridView uses virtualization of its visual elements. So, only the cells and rows currently visible at the form have a VisualElement. The only place where it is secure to access the VisualElement property is the RowFormatting event. Here is a sample:

void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e) 
    if (e.RowElement.IsCurrent || e.RowElement.IsSelected) 
    { 
        e.RowElement.DrawFill = true
        e.RowElement.BackColor = Color.SkyBlue; 
    } 
    else if ((int)e.RowElement.RowInfo.Cells[0].Value > 10) 
    { 
        e.RowElement.BackColor = Color.Green; 
        e.RowElement.DrawFill = true
    } 
    else 
    { 
        e.RowElement.DrawFill = false
    } 
 

Should you have any other questions, do not hesitate to write us back.

All the best,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alfonsina
Top achievements
Rank 1
answered on 05 Jul 2012, 12:15 PM

Hello Telerik Team,

I want to set a value to a cell in a GridView like this:

savedRow.Cells["Treffer"].Value = numberHits;

savedRow has the type GridViewRowInfo. The problem hier is that the cell is not setted by the value numberHits. The cell is empty.

How can I solve this problem?

Thanks very much.

Kind regards,

Alfonsina

0
Jack
Telerik team
answered on 09 Jul 2012, 12:35 PM
Hi Alfonsina,

Such an issue may occur when the cell data type is different from numberHits data type and result of the implicit conversion is null. However, I am not able to make precise suggestions without investigating your code. Please, could you send me a sample application where the issue appears and I will try to find a proper solution.

I am looking forward to your reply.
 
Greetings,
Jack
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
Christopher
Top achievements
Rank 1
Answers by
Jack
Telerik team
Alfonsina
Top achievements
Rank 1
Share this question
or