Multi-column combobox automatically picks the first item

1 Answer 724 Views
MultiColumn ComboBox
y2kdis
Top achievements
Rank 1
y2kdis asked on 08 Apr 2022, 01:04 AM

Hi,

I have a multi-column combobox that is data-bound to a binding source control.

Then in the form code I have the following lines:

Me.RadMultiColumnComboBox1.DropDownStyle = RadDropDownStyle.DropDownList
Me.RadMultiColumnComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend
Me.RadMultiColumnComboBox1.SelectedIndex = -1

The last line, in particular, is important in our case because we want to prevent the selection of the first record by default. Everything works fine except when there's only one record in the list.

When that happens, the textbox element picks up the display member of the lone item as soon as the user clicks the drop-down arrow. The text remains after the pop-up closes even if the user does not explicitly select the solo record.  This gives the user the false impression that a value has been set, but in reality the underlying value is still null.

We then found out that the second line of code above is what is causing this unwanted behavior. When commented out, an MCCB with a single record does not exhibit the problem.

We would like to keep the SuggestAppend feature working (i.e., in the case of multiple records), so is there a way to resolve this issue without having to resort to checking the number of records in the list?

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 08 Apr 2022, 12:46 PM

Hi Sidky Macatangay,

Thank you for the provided details.

What you could try is to initially set the EditorControl.CurrentRow property of the grid inside the drop-down to null. Then you can subscribe to the PopupOpened and PopupClosed event of the RadMultiColumnComboBox. Inside the event handler, you can check if the CurrentRow property is null. If yes, reset the Text property of the control.

this.radMultiColumnComboBox3.MultiColumnComboBoxElement.PopupOpened += MultiColumnComboBoxElement_PopupOpened;
this.radMultiColumnComboBox3.MultiColumnComboBoxElement.PopupClosed += MultiColumnComboBoxElement_PopupClosed;

private void MultiColumnComboBoxElement_PopupClosed(object sender, RadPopupClosedEventArgs args)
{
    if (this.radMultiColumnComboBox3.EditorControl.CurrentRow == null)
    {
        this.radMultiColumnComboBox3.Text = "";
    }
}

private void MultiColumnComboBoxElement_PopupOpened(object sender, EventArgs e)
{
    if (this.radMultiColumnComboBox3.EditorControl.CurrentRow == null)
    {
        this.radMultiColumnComboBox3.Text = "";
    }
}

Give this approach a try and let me know if it works for you.

Regards,
Dinko
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.

y2kdis
Top achievements
Rank 1
commented on 08 Apr 2022, 04:54 PM

It does work but not as clean as we would like it to be.

Because it just resets the text to an empty string, there's still a split-second display of the lone record's text which gives an impression of a system/form glitch.

Is there a work around to that or can you suggest an alternative?

Dinko | Tech Support Engineer
Telerik team
commented on 13 Apr 2022, 09:01 AM

it is strange that I wasn't able to observe this flash behavior. Just for the test can you try the same code but subscribe to the PopupOpening and PopupClosing events. Give this a try and let me know how it goes. In the meantime, I will try to find another approach for your requirement.
y2kdis
Top achievements
Rank 1
commented on 14 Apr 2022, 04:23 PM

I'm getting the same result when I moved the code to the opening and closing events.
Dinko | Tech Support Engineer
Telerik team
commented on 18 Apr 2022, 01:17 PM

I have discussed your scenario with our development team and we agree that this behavior is unexpected. The Text property should respect the CurrentRow of the EditorControl in this case. That is why I have logged this in our Feedback Portal where you can track its progress. I have updated your Telerik Points for bringing this to our attention.

As for a workaround, you can try subscribing to the TextChanged event of the MCCB. Inside the event handler, you can check if the CurrentRow is null. If yes, clear the Text property.

private void RadMultiColumnComboBox1_TextChanged(object sender, EventArgs e)
{
    if(this.radMultiColumnComboBox1.EditorControl.CurrentRow == null)
    {
        this.radMultiColumnComboBox1.Text = "";
    }
}

An alternative solution is to change the color of the Text. You could subscribe to the SelectedIndexChanged event of the control. Inside the event handler, you can check the SelectedIndex and change the ForeColor of the Text depending on this property. In this case, the subscription of the event needs to be set before setting the CurrentRow to null.

private void RadMultiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (this.radMultiColumnComboBox1.SelectedIndex < 0)
    {
        this.radMultiColumnComboBox1.MultiColumnComboBoxElement.TextboxContentElement.ForeColor = Color.White;
    }
    else
    {
        this.radMultiColumnComboBox1.MultiColumnComboBoxElement.TextboxContentElement.ForeColor = Color.Black;
    }
}

I hope that one of these approaches will work for you.

Tags
MultiColumn ComboBox
Asked by
y2kdis
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or