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

Gridview update

1 Answer 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 12 Jul 2010, 02:45 PM
We have this scenario where we load the gridview at load time from XML.
Multiple grids need to be updated at load time straight after the data has been created.
If the gridviews are on tabs only the first active tab is immediatly accessible

I can't seem to get access to the cells that should already be rendered on the grid the column count is 5 but the cell return is null.

Help please

please see example

 

 

// ===============================================================================

 

 

 

// Load the service information

 

 

 

//================================================================================

 

 

 

var mydata4 = from info in odoc.Descendants("PG").Elements("SER").Elements("PS")

 

 

 

select new Service

 

{

Servicer =

 

Convert.ToString(info.Element("B").Attribute("V").Value),

 

Reason =

 

Convert.ToString(info.Element("R").Attribute("V").Value),

 

Invoice =

 

Convert.ToString(info.Element("I").Attribute("V").Value),

 

Submitted =

 

DateTime.ParseExact(Convert.ToString(info.Element("D").Attribute("V").Value), "yyyyMMdd", CultureInfo.InvariantCulture),

 

Cost =

 

Convert.ToDouble(info.Element("A").Attribute("V").Value),

 

 

};

 

 

 

 

foreach (Service serv in mydata4)

 

{

serviceList.Add(serv);

}

radGridView3.ItemsSource = serviceList;

radGridView3.Rebind();

 

 

 

// Now that we've loaded the data grid we need to populate the errors if there are any found

 

 

 

var recs = from info in odoc.Descendants("PG").Elements("SER").Elements("PS") select info;

 

 

 

int count = 0;

This section is returning nulls in the GridViewCell

 

 

 

foreach (var record in recs)

 

{

 

 

GridViewCell temp = GetCellByIndecies(radGridView3, count, 0);

 

 

 

 

count++;

 

}


 

 

 

public GridViewCell GetCellByIndecies(RadGridView GridView, int rowIndex, int columnIndex)

 

{

 

 

return

 

 

 

 

 

(

 

from cell in GridView.ChildrenOfType<GridViewCell>()

 

 

 

where GridView.Columns.IndexOf(cell.Column) == columnIndex

 

 

 

select cell).Skip(rowIndex).FirstOrDefault();

 

}

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Jul 2010, 05:05 PM
Hello Nick,

 
The problem in this case comes from the fact that not all elements of the grid are created right after changing of the ItemsSource. That is why you receive a "null" result for the cell you are trying to get. A possible workaround would be to invoke a Dispatcher like following:

int count = 0;
this.Dispatcher.BeginInvoke(new Action(                            
() =>
{
    foreach (var item in this.playersGrid.Items)
    {
    GridViewCell temp = GetCellByIndecies(this.radGridView3, count, 0);                     
    count++;
    }}
       ),
 null);

However, working with the visual elements is not quite recommended method for getting/setting values as it may result in disabling of the virtualization. 
A good approach in your case would be to apply validation instead. You can use this blog post as a reference on this topic. However, considering your scenario that you need a validation on more than one items, this suggested method is applicable only with our latest release Q2 2010.



Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Nick
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or