I have a krypton combo box which I data bind with a list of key-value pairs. What's happening is that when I set the selected item in code, it is highlighting the text. How can I prevent this or deselect the text?
I've tried the following:
// 1
combo.Select(0,0);
// 2
combo.Focus();
anotherControl.Focus();
// 3
combo.SelectionStart = 0;
combo.SelectionLength = combo.Text.Length;
// 4
combo.SelectionStart = combo.Text.Length;
combo.SelectionLength = 0;
Nothing seems to work. Any help is appreciated.
I managed accomplishing this be overriding the OnPaint event of my control/window and doing
combobox1.SelectionLength = 0;
I may have found a solution that works:
If you are using a form, subscribe to the form's Shown event.
OR
If you are using a UserControl (like I am), you can subscribe to the VisibleChanged event.
In the event, you can then do the following:
foreach (ComboBox cbo in (this.Controls.Cast<Control>().Where(c => c is ComboBox).Select(c => (ComboBox) c)))
{
cbo.SelectionLength = 0;
}
As an aside:
I ended up having to do this for a user control in which I added ComboBoxes to the control and then needed to later dynamically set their size. Setting the size caused the highlighting that the OP was encountering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With