Persist Change in RadDropDownListEditor with empty string.

1 Answer 166 Views
DropDownList GridView
Shubham
Top achievements
Rank 1
Iron
Shubham asked on 24 Dec 2021, 02:32 PM

Hi,

I am using a RadGridView in a window .

I am using RadDropDownListEditor for editing one of the cells in the column that has one element as list.

I want it to be able to set as empty on editingBut the change isn't persisting when I provide empty string.

According to the documentation, the change only persists when we select one of the other items in the list.

Is there any way I can set it as blank on providing empty string.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Dec 2021, 07:53 AM

Hello, Shubham,

According to the provided information, I suppose that you are using a GridViewComboBoxColumn. Please have in mind that this column type accepts only valid values according to the applied GridViewComboBoxColumn.DataSource collection. If the editor's value is not present in the column's DataSource, it is not expected to be preserved when exiting the cell's edit mode. 

I have tested setting the column's DropDownStyle property to DropDown which enables editing in the editor. If the test is cleared, the empty value is stored: 

        public RadForm1()
        {
            InitializeComponent();
            GridViewComboBoxColumn comboCol = new GridViewComboBoxColumn("Combo");
            comboCol.DataSource = new List<string>() { "one", "two", "three" };
            comboCol.ValueMember = "SupplierID"; 
            comboCol.Width = 200;
            comboCol.DropDownStyle = RadDropDownStyle.DropDown;
            this.radGridView1.Columns.Add(comboCol);
        }

If the above solution doesn't work for your scenario, there are two general approaches that can be followed in this case: 

1. Add the specific values (e.g. empty string, or "-") to the GridViewComboBoxColumn.DataSource collection so they will be valid. Thus, the GridViewComboBoxColumn.DataSource collection will contain all the entered empty value.

2. Use a GridViewTextBoxColumn. Since the default editor for the GridViewTextBoxColumn is RadTextBoxEditor, it is necessary to be replaced with a RadDropDownListEditor in the EditorRequired event. It is necessary to specify the editor's DataSource, DisplayMember and ValueMember properties in a similar way like you do it for the GridViewComboBoxColumn. A sample code snippet for this approach is available in the second section of the following KB article:

https://docs.telerik.com/devtools/winforms/knowledge-base/display-text-for-invalid-values-in-grid-combobox-column 

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

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Shubham
Top achievements
Rank 1
Iron
commented on 28 Dec 2021, 02:40 PM

Hi Dess,
Thanks for the Response.

I am sorry , I didn't provide this detail earlier, I am using GridViewTextBoxColumn and I am casting it to a RadDropDownListEditor in the CellEditorInitialized event.

I saw the article and I don' want to add an empty string in the datasource.
How do I make sure that empty string persists after editing as it is not clear to me from the article.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 29 Dec 2021, 07:43 AM

Hi, Shubham,

I have attached my sample project for your reference. Please give it a try and see how it works on your end with the empty value in the drop down editor. The observed result on my end was illustrated in the gif file above. The empty string is preserved in the cell after editing.

Tags
DropDownList GridView
Asked by
Shubham
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or