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

GridViewComboBoxColumn does not clear properly

5 Answers 228 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 16 May 2013, 03:31 AM
I have a GridViewComboBoxColumn with AutoCompleteMode = SugestAppend, and DropDownStyle = DropDown, and a DataSource of a DataSet with a blank record at the top (so a selection can be removed). If you use the drop down button and select the blank entry then the cell in the GridView clears as expected.  However, if you clear the data in the cell instead, it does not select the blank entry in the drop down list, and when you tab away from that cell the value goes back to what it was before the delete.

5 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 18 May 2013, 07:49 PM
Hello Sean,

A very simple workaround for this could be just registering to the CellEditorInitializedEvent and do the following:
void gridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    var editor = e.ActiveEditor as RadDropDownListEditor;
    if (editor != null)
    {
        var editorElement = editor.EditorElement as RadDropDownListEditorElement;
        if (editorElement != null)
        {
            editorElement.TextChanged -= editorElement_TextChanged;
            editorElement.TextChanged += editorElement_TextChanged;
        }
    }
}
 
void editorElement_TextChanged(object sender, EventArgs e)
{
    var editorElement = sender as RadDropDownListEditorElement;
    if (editorElement != null)
    {
        if (string.IsNullOrEmpty(editorElement.Text))
        {
            editorElement.SelectedIndex = 0;
        }
    }
}

Whenever an item that is not in the list will be selected, the editor.Element.Text will be string.emply so we will just set the first item as selected, thus having an emply selection.

Hope this helps.

Best Regards,
Emanuel Varga MVP
Michael
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 30 Jun 2024, 01:04 PM

I tried this, but a very weird thing happened:  The sender argument to editorElement_TextChanged was not, in fact, a RadDropDownListEditorElement.  It was a RadPropertyGrid.  So of course the code didn't work.  That seems like a straight-up bug to me.  I'm using UI.for.WinForms.AllControls.Net48 2023.2.718.

Also, I've tried setting the dropdown's SelectedIndex to -1, but that seems to have no effect.  I've tried doing this from ValueChanged and TextChanging, since TextChanged doesn't work, but nothing worked.

Dinko | Tech Support Engineer
Telerik team
commented on 03 Jul 2024, 07:48 AM

Hi Michael,

You mentioned that the sender argument in the TextChanged event was not RadDropDownListEditorElement, but a RadPropertyGrid. I am a little confused here as the RadGridView does not directly use the RadPropertyGrid as its editor. 

I will be happy to help you and investigate this behavior. However, this thread is quite old and it will be better to create a new one and share more details regarding your scenario and the behavior that you are experiencing. Isolating it in a sample project will be of great help. This way I can better understand it and debug it on my side. 

0
Peter
Telerik team
answered on 20 May 2013, 01:09 PM
Hi Sean,

Thank you for your question.

The Text property is not synchronized out of the box with the SelectedIndex property and you should use the solutioin Emanuel proposed.

@Emanuel - thank you for your cooperation. 

Regards,
Peter
the Telerik team
RadChart for WinForms is obsolete. Now what?
0
Sean
Top achievements
Rank 1
answered on 20 May 2013, 09:01 PM
G'Day Peter,

Yes the work around works but as far as I am concerned this is a bug that needs to be resolved.  Any text entered will be matched and verified against the list but empty text is not. Shouldn't the behaviour be the same as a stand alone control?

Thanks,
Sean
0
Peter
Telerik team
answered on 23 May 2013, 03:19 PM
Hi Sean,

Thank you for sharing your opinion with us.

We will consider including this when planning our future releases, if there is a demand for such a functionality. For the time being, you can continue using the provided workaround which covers this case.

Let me know if you have additional questions.

Regards,
Peter
Telerik
RadChart for WinForms is obsolete. Now what?
0
Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
answered on 11 Nov 2022, 10:03 AM

Is this problem still present? I am having the same problem. If the user empties the text the value remains unchanged, if the user chooses the empty value in the dropdown menu, then the value empties.

 

Alessandro

Dinko | Tech Support Engineer
Telerik team
commented on 16 Nov 2022, 08:31 AM

Hi Alessandro,

This question is a duplicate of one from your support ticket thread. I am sharing the answer also here so that the community can take advantage of it.

When an empty string is present in the drop-down list of the control, clearing the value will not set an item that contains an empty string. The RadDropDownListEditor control string comparison mechanism does not expect to have an empty string. Let me try to explain:

  • When an empty string item is NOT present in the drop-down collection: In this case, when the cell commits its value, the internal logic of the control will check if the Text is different from the empty string and perform a search comparison operation to find a match. No match will be found and the SelectedIndex will be set to -1.
  • When an empty string item is present in the drop-down collection: The path here is the same as the above one. The difference here is that the string comparison method will find an item that will be the first one in your case. In this scenario, the SelectedIndex won't be set to -1 and the previous valid value will be returned.

This can be workaround by avoiding using empty strings. You can set space or "-" or any other symbol.

new CLuogo { id = 0, codice = "", nome = " " },

OR

new CLuogo { id = 0, codice = "", nome = "-" },

This behavior was discussed with the development team and it was concluded that there is room for improvement. That is why I have logged it in our Feedback Portal where you can track its progress and vote for its implementation. By voting, you are increasing its priority.

Tags
GridView
Asked by
Sean
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Peter
Telerik team
Sean
Top achievements
Rank 1
Alessandro
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or