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

RadGridview : CustomCell Replicates in other Cell when Scrolling

1 Answer 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deepak Chauhan
Top achievements
Rank 1
Deepak Chauhan asked on 19 Oct 2012, 12:37 PM
I was able to create Customcell element from the following post.
http://www.telerik.com/community/forums/winforms/gridview/show-mulitple-images-in-a-gridview-column.aspx

But when I perform scroll in Gridview, the same CustomCell with 3 Buttons replicate itself in other cells.
Here is my code for CreateCell Event.

private void gvProductDetail_CreateCell(object sender, GridViewCreateCellEventArgs e)
        {
            if (e.Column.GetType().Name == "GridViewCommandColumn")
            {
                GridViewCommandColumn dataColumn = e.Column as GridViewCommandColumn;


                if (e.Row is GridDataRowElement && dataColumn != null)
                {
                    CustomGridDataCell cell = new CustomGridDataCell(e.Column, e.Row);
                    e.CellElement = cell;
                }
            }
        }

Please guide Me. Thanks in Advance.

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 23 Oct 2012, 01:08 PM
Hello Deepak,

I assume that the issue is caused by the fact that you have more than one command column and you want to apply custom cell only for one of them. In that case, I recommend creating a custom column which will address this misbehavior:
public class GridMultiCommandColumn : GridViewDataColumn
    {
        public GridMultiCommandColumn()
            : base()
        {
            this.ReadOnly = true;
        }
 
        public GridMultiCommandColumn(string fieldName)
            : base(fieldName)
        {
 
        }
 
        public GridMultiCommandColumn(string uniqueName, string fieldName)
            : base(uniqueName, fieldName)
        {
 
        }
 
        public override Type GetCellType(GridViewRowInfo row)
        {
            if (row is GridViewDataRowInfo)
            {
                return typeof(CustomGridDataCell);
            }
 
            return base.GetCellType(row);
        }
    }

In addition, you should override the IsCompatible method of the custom cell in the following way:
public override bool IsCompatible(GridViewColumn data, object context)
{
        return data is GridMultiCommandColumn && context is GridDataRowElement;
}

Note that in this approach, you do not need to use the CreateCell event. You should use the custom column instead of the GridViewCommandColumn. All the best,
Svett
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
Tags
GridView
Asked by
Deepak Chauhan
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or