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

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

1 Answer 338 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Santosh
Top achievements
Rank 1
Santosh asked on 31 Jul 2019, 07:11 AM

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()
       {
           base.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
           };
           this.radDropDownList.Items.Add("Santosh");
           this.radDropDownList.Items.Add("Jha");
            this.radDropDownList.Items.Add("Mr");
           this.radDropDownList.Items.Add("Kumar");
           this.Children.Add(radDropDownList);
       }
 
       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
       {
           get
           {
               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.Add(customColumn);
           this.radGridViewTable.Columns["Destination Table"].MinWidth = 165;

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Aug 2019, 12:17 PM
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. 

Regards,
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.
Tags
GridView
Asked by
Santosh
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or