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

sorting problem while RadGridView have disabled command buttons

2 Answers 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Omar
Top achievements
Rank 2
Omar asked on 02 Dec 2014, 07:25 AM
some of buttons disabled and another buttons are enabled depending on condition 
the problem is , if you sort the radgridview by clicking the header of data column these enabled buttons will be disabled and disabled buttons somtimes will be enabled , i tried ViewCellFormatting event but have the same problem.
You can see the attached screenshot before and after sorting ..
 private void grvDepartment_CellFormatting(object sender, CellFormattingEventArgs e)
        {            
            if (e.RowIndex > -1) // not header
            {
                var cellElement = e.CellElement;
                int departmentId = Convert.ToInt32(e.Row.Cells["DepartmentId"].Value);                
                ICollection<UserProfile> usersProfiles =
                     (from u in _outEntities.UserProfile.Local where u.DepartmentId == departmentId select u).ToList();

                if (usersProfiles.Count > 0)
                {
                    #region MyRegion
                    if (cellElement.ColumnInfo.Name == "DepartmentName")
                        cellElement.Enabled = false;
                    else if (cellElement.ColumnInfo.Name == "DepartmentAcronum")
                        cellElement.Enabled = false;
                    else cellElement.Enabled = true; 
                    #endregion

                    var cell = cellElement as GridCommandCellElement;
                    if (cell != null)
                    {
                        #region MyRegion
                        if (cell.ColumnInfo.Name == "colUpdate")
                            cell.Enabled = false;
                        //cell.Visibility = ElementVisibility.Hidden;
                        else if (cell.ColumnInfo.Name == "colDelete")
                            //cell.Visibility = ElementVisibility.Hidden; 
                            cell.Enabled = false;
                        else cell.Enabled = true;
                        //cell.Visibility = ElementVisibility.Visible;
                        #endregion
                    }
                }
            }            
        }



2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 04 Dec 2014, 12:28 PM
Hi Omar,

Thank you for writing.

RadGridView uses UI virtualization
 for its cells, which means that there are only certain amount of cells visible at all times and the data in these cells is being changed when scrolling, sorting, fiktering. Hence it is necessary to reset each visual settings you apply. More information and examples you can find here: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Omar
Top achievements
Rank 2
answered on 10 Dec 2014, 06:05 AM
Thanks for this post.
Tags
GridView
Asked by
Omar
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Omar
Top achievements
Rank 2
Share this question
or