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

[Solved] issue with ItemsControl property for grid....

5 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Deepak Garla
Top achievements
Rank 1
Deepak Garla asked on 04 Nov 2009, 02:11 PM
Hi,

 i was using telerik Q2 version earlier. My code below was working fine then

 

  foreach (object item in this.radgrdUserdetails.Items)

 

    {

 

        GridViewRow row = this.radgrdUserdetails.ItemsControl.ItemsGenerator.ContainerFromItem(item) as GridViewRow;

 


        if

 

(row != null)

 

        {

 

        

 

            // business logic

 

 

    
        }


}

The above code converts the each item in grid into a GridViewRow row.
 
The same code is not working when i am using this with Q3 Beta version Dll's.

Its not detecting  "ItemsControl".

 

GridViewRow row = this.radgrdUserdetails.ItemsControl.ItemsGenerator.ContainerFromItem(item) as GridViewRow;

 

.

i also tried 
        

GridViewRow

 

row = this.radgrdUserdetails.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow;
even this is not woking as wished...


Please help me with this...

Regards,
Deepak Garla.






 

5 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 04 Nov 2009, 02:51 PM
Hello Deepak Garla,

There is a new property on RadGridView called ItemsGenerator. Could you please use this property instead.

var container = this.gridView.ItemsGenerator.ContainerFromItem(myItem)
// instead of
var container = this.gridView.ItemsControl.ItemsGenerator.ContainerFromItem(myItem)


All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Deepak Garla
Top achievements
Rank 1
answered on 04 Nov 2009, 03:33 PM
Hi milan.
Thanks for an early reply....

I have been using the code below........

 

foreach (object item in this.radgrdUserdetails.Items)

 

{

 

 

GridViewRow row = this.radgrdUserdetails.ItemsGenerator.ContainerFromItem(item) as GridViewRow;

 

 

if (row != null)

 

{

 

GridViewCellBase cell1 = (from c in row.Cells

 

 

where c.Column.UniqueName == "businessRoles"

 

 

select c).FirstOrDefault();

 

 

if (cell1 != null)

 

{

cell1.IsEnabled =

false;

 

}

 

}
}

it  is still not working, only for first  few rows the is enabled property is  set to false.The rest is true.......


the same code is working fine with q2 version...

 

0
Milan
Telerik team
answered on 05 Nov 2009, 01:49 PM
Hi Deepak Garla,

You should run the logic to disable cells every time a row is loaded. To achieve that you can use the RowLoaded event like this:

void gridView_RowLoaded(object sender, RowLoadedEventArgs e)
{
    if (e.Row is GridViewGroupRow || e.Row is GridViewHeaderRow || e.Row is GridViewNewRow)
        return;
  
    this.DisableCells(e.Row as GridViewRow);
}
  
private void DisableCells(GridViewRow row)
{
    if (row != null)
    {
  
        GridViewCellBase cell1 = (from c in row.Cells
                                  where c.Column.UniqueName == "businessRoles"
                                  select c).FirstOrDefault();
  
        if (cell1 != null)
        {
            cell1.IsEnabled = false;
        }
    }
}

Hope this helps.

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Deepak Garla
Top achievements
Rank 1
answered on 05 Nov 2009, 03:01 PM
hi milan,
Thaks for the reply,but unfortunately the code is not workiong...


this.DisableCells(e.Row as GridViewRow);


e.row in the above line is always null....

so none of the rows are getting locked...
any other approach for this?
0
Milan
Telerik team
answered on 06 Nov 2009, 09:40 AM
Hello Deepak Garla,

It is very strange that the e.Row property is always null. Could you send us a project that will help us reproduce the problem?


Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Deepak Garla
Top achievements
Rank 1
Answers by
Milan
Telerik team
Deepak Garla
Top achievements
Rank 1
Share this question
or