Adding Custom control in a Cell of GridView - which contains DropdownList

2 posts, 0 answers
  1. Santosh
    Santosh avatar
    1 posts
    Member since:
    Jul 2019

    Posted 31 Jul 2019 Link to this post

    Hi All, 

    I have added a custom column or cell containing DrodownList -its appearing correctly in view mode. 

    Now I have below points :

    1. On which event of the GridView I can bind the dropdownList. 

    2. When I select any value (Currently have added some static value in the DropdownList). Once I scroll the grid , the state changes to original state. 

    3. Some time I noticed that the value i selected for let say row one, the same value is being selected for the the row which is not displayed. after scrolling we can see the same. and the value of 1st row got removed. 

    4. My requirement is -

    1.     I need to give a data source to the Drodownlist. 
    2.  Need to get a value selected on some condition 
    3. If I scroll the value should not change. 

    Attaching my code of custom cell 

    class CustomDropCell : GridDataCellElement
           private string conString { get; set; }
           public CustomDropCell(GridViewColumn column, GridRowElement row): base(column, row)
               //conString = con;
           private StackLayoutPanel panel;
           private RadDropDownListElement radDropDownList;
           protected override void CreateChildElements()
               this.panel = new StackLayoutPanel();
               this.panel.Margin = new System.Windows.Forms.Padding(5);
               this.panel.Orientation = System.Windows.Forms.Orientation.Vertical;
               this.radDropDownList = new RadDropDownListElement
                   DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList
           protected override void SetContentCore(object value)
               GridViewGroupRowInfo row = this.RowInfo as GridViewGroupRowInfo;
               object cellValue = value;
               if (cellValue is DBNull || cellValue == null)
                   cellValue = "Mr";
               this.radDropDownList.SelectedValue = cellValue;
           protected override Type ThemeEffectiveType
                   return typeof(GridDataCellElement);
           public override bool IsCompatible(GridViewColumn data, object context)
               return base.IsCompatible(data, context);
               // return data is CustomDropCellColumn && context is GridDataRowElement;
       public class CustomDropCellColumn : GridViewDataColumn
           //private string conString { get; set; }
           public CustomDropCellColumn(string fieldName) : base(fieldName)
               //conString = connectionString;
           public override Type GetCellType(GridViewRowInfo row)
               if (row is GridViewDataRowInfo)
                   return typeof(CustomDropCell);
               return base.GetCellType(row);


    Adding the column in Grid in Form Constructor.

    CustomDropCellColumn customColumn = new CustomDropCellColumn("Destination Table");
               customColumn.MaxWidth = 170;
               this.radGridViewTable.Columns["Destination Table"].MinWidth = 165;
  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    3988 posts

    Posted 02 Aug 2019 Link to this post

    Hello, Santosh, 

    Your question has already been answered in the support thread you have opened on the same topic. However, I am posting the answer here as well in order the community to benefit from it. We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread. Thank you for your understanding.

    Note that RadGridView uses data virtualization and visual cell elements are created only for the currently visible cells which are being reused during operations like scrolling. If you have a look at the attached sample project, you will notice that in the SetContentCore method of the custom GridDataCellElement the SelectedValue of RadDropDownList is synchronized with the value of the associated data cell. This is the appropriate way to load the correct selected value after scrolling. When you change the selected item, it is important to update the value of the data cell in order to obtain the correct value after scrolling as well.

    This is the proper mechanism for keeping the correct values in the custom cell elements.

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top