To reproduce:
Populate the AutoCompleteBox and start a search returning enough results to need the scrollbar. When clicking and dragging the scroll bar to scroll - if the cursor is not positioned directly over the scrollbar at the time you release the mouseclick, the dropdown list is closed an item is added to the selection.
Workaround:
public partial class Form1 : Form
{
bool isMouseDown = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
AddAutoCompleteItems();
radAutoCompleteBox1.ListElement.VScrollBar.MouseDown += ListElement_MouseDown;
radAutoCompleteBox1.ListElement.VScrollBar.MouseUp += ListElement_MouseUp;
radAutoCompleteBox1.TokenValidating += radAutoCompleteBox1_TokenValidating;
}
void radAutoCompleteBox1_TokenValidating(object sender, TokenValidatingEventArgs e)
{
e.IsValidToken = !isMouseDown;
isMouseDown = false;
}
void ListElement_MouseUp(object sender, MouseEventArgs e)
{
RadListVisualItem el = radAutoCompleteBox1.ListElement.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (el != null)
{
return;
}
isMouseDown = false;
}
void ListElement_MouseDown(object sender, MouseEventArgs e)
{
isMouseDown = true;
}
private void AddAutoCompleteItems()
{
RadListDataItemCollection items = this.radAutoCompleteBox1.AutoCompleteItems;
items.Add(new RadListDataItem("Joe Smith", "joe@fakecompany.com"));
items.Add(new RadListDataItem("Adam Petersen", "adam@qwerty.com"));
items.Add(new RadListDataItem("Jack Russel", "jack@russel.nocom"));
items.Add(new RadListDataItem("Daniel Finger", "daniel.pinger@gmail.com"));
items.Add(new RadListDataItem("Richard Vail", "rvail@richardvail.com"));
items.Add(new RadListDataItem("Sebastian Jonnson", "s.jonnson@sjonnson.com"));
items.Add(new RadListDataItem("Lee Cooper", "lee.cooper@coopercoorp.com"));
items.Add(new RadListDataItem("Kelvin Clain", "kclain@clainkevin.com"));
items.Add(new RadListDataItem("Maria Jenson", "mjenson@mariajenson.com"));
items.Add(new RadListDataItem("Chelsea Maarten", "chelsea@maarten.com"));
items.Add(new RadListDataItem("Jenson Chew", "jenson.chew@nospam.com"));
items.Add(new RadListDataItem("Martin Williams", "m.williams@martinandwilliams.com"));
items.Add(new RadListDataItem("Telerik", "clientservice@telerik.com"));
items.Add(new RadListDataItem("James Stone", "james.stone@manystones.com"));
items.Add(new RadListDataItem("Samuel Jackson", "samuel.jackson@nojackson.com"));
}
}
public class MyRadAutoCompleteBox : RadAutoCompleteBox
{
protected override RadTextBoxControlElement CreateTextBoxElement()
{
return new MyRadAutoCompleteBoxElement();
}
}
public class MyRadAutoCompleteBoxElement : RadAutoCompleteBoxElement
{
protected override TextBoxViewElement CreateViewElement()
{
return new MyAutoCompleteBoxViewElement();
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(RadAutoCompleteBoxElement);
}
}
}
public class MyAutoCompleteBoxViewElement : AutoCompleteBoxViewElement
{
protected override int InsertTokenizedTextBlocks(int index, string text, bool performInvalidation)
{
bool isValid = performInvalidation ? this.OnTokenValidating(text) : true;
if (!isValid)
{
return index;
}
return base.InsertTokenizedTextBlocks(index, text, performInvalidation);
}