I've used the AutoCompleteBox on a WPF form. Now I would like to do the thing inside a WPF DataGrid. Almost everything works except the SelectedItem was not work.
In the XAML below I have added a code behind handler for LostFocus on Autocompletebox .
AutoCompleteBox autoBox = sender as AutoCompleteBox;if (autoBox == null)
return;
TextBox textBox = autoBox.Template.FindName("Text", autoBox) as TextBox;
textBox.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x33, 0x33, 0x33));
Mouse.OverrideCursor = Cursors.Wait;
if (txtAccount.SelectedItem != null)
{
if (txtAccount.Text.Length > 0)
{
if (txtAccount.Text.Contains(" "))
{
loadAccount(0);
calculatePrice();
}
else
MessageBox.Show("Invalid account!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
MessageBox.Show("Please enter text account!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
ddlVehicle.Focus();
}
Mouse.OverrideCursor = Cursors.Arrow;
here 'txtAccount.SelectedItem' is given null value ...
Please suggest how to get selecteditem on autocompletebox.