GridViewComboBoxColumn - end edit on item selection

1 Answer 30 Views
GridView
Marian
Top achievements
Rank 2
Iron
Iron
Iron
Marian asked on 05 Jul 2024, 01:27 PM

Hello,

I would like to help with GridViewComboBoxColumn behavior. I have almost solved how to automatically show popup on click. Next, I want to end edit after selecting some item from combo box, similar to standard DataGridView behavior. I have done this so far:

private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
	// automatic combo expanding
	if (radGridView1.IsInEditMode)
		return;

	var cell = sender as GridComboBoxCellElement;
	if (cell == null)
		return;

	radGridView1.BeginEdit();
	var editor = cell.Editor as RadDropDownListEditor;
	if (editor == null)
		return;

	var el = editor.EditorElement as RadDropDownListEditorElement;
	if (el == null)
		return;

	el.SelectedIndexChanged += El_SelectedIndexChanged;

	el.ShowPopup();
}

private void El_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
	var el = sender as RadDropDownListEditorElement;
	if(el == null) 
		return;

	radGridView1.EndEdit();
	el.SelectedIndexChanged -= El_SelectedIndexChanged;
}

I attach SelectedIndexChanged event handler to RadDropDownListEditorElement before showing popup. In this handler, I call EndEdit first and then detach the handler. This works ok except for one case, when user selects the same item, in this case SelectedIndexChanged is not fired, because SelectedIndex hasn't changed:

I tried the same with other events like PopupClosed, but when I cal EndEdit in these events, selected value is not commited. Is it possible to do this somehow? I have attached test project, TelerikTestReal in solution. Thanks.

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 09 Jul 2024, 01:52 PM

Hello, Marian,

The provided project is greatly appreciated.

To achieve the desired behavior, I can suggest to handle the MouseUp event of the list control and call the EndEdit() in the following way:

el.ListElement.ElementTree.Control.MouseUp += Control_MouseUp;
private void Control_MouseUp(object sender, MouseEventArgs e)
{
    radGridView1.EndEdit();
}

Thus, the selection will be changed and the popup will close in all cases. You can also remove the SelectedIndexChanged event in this case, since it wouldn't be nesessary. 

I am also attaching the TelerikTestReal project updated. 

I hope this helps. If you have any other questions, please let me know.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Marian
Top achievements
Rank 2
Iron
Iron
Iron
commented on 11 Jul 2024, 03:08 PM

Thanks, it works. But I tried to handle KeyDown event in similar way to end edit on Enter key, but this doesn't work, it closes just popup, probably after Enter that ListElement etc is no longer valid. I solved it by handling PopupClosed of RadDropDownListEditorElement, and this works. I tried this event before, but it wasn't working properly fo mouse click, for Enter key it seems to be ok.

private void El_PopupClosed(object sender, RadPopupClosedEventArgs args)
{
	if (radGridView1.IsInEditMode)
		radGridView1.EndEdit();
}

Marian
Top achievements
Rank 2
Iron
Iron
Iron
commented on 11 Jul 2024, 03:49 PM

Sorry, I haven't tested it enough, after handling PopupClosed, ending edit with MouseUp is no longer working. So, I don't know, how to handle Enter properly in this scenario? But the mouse selection is important for me, maybe I can let this as it is.
Nadya | Tech Support Engineer
Telerik team
commented on 16 Jul 2024, 07:16 AM

Hello, Marian,

Reading your latest posts, I get a little confused about what is working and what you would like to improve. Can you please provide more information is the suggested solution for handling ListElement.ElementTree.Control.MouseUp is working for you. Note, that this approach handles the case when the popup closes upon having a selected item. If I understand correctly this is fine for you but you have difficulties doing the same with the Enter key, am I right. 

I tested the Enter key behavior on my end and it closes the pop up as you expect. Please see the attached gif file. Am I missing something? Which are the exact steps that you follow to close the popup?

Looking forward to your reply.

Tags
GridView
Asked by
Marian
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or