Hello,
when I enter a value and it matches only one entry in the autocomplete dropdown list the dropdownbox will be closed, but the SelecedIndexChanged event of the DropDownList control will not fired.
Only when I select a entry in the dropdown box the event will be fired.
For example I enter "Germany", one item matches and the dropdownbox closing. The SelectedIndexChanged event will not fired. It will be fired after leaving the control by tab key or click another control like a button.
When I enter "Germ" two items matches. When I select one the dropdown closing and the SelectedIndexChanged event will be fired.
Why the SelectedIndexChanged event will not fired? It have to fire or not? How to solve?
Here is my code:
Regards,
Ralf
when I enter a value and it matches only one entry in the autocomplete dropdown list the dropdownbox will be closed, but the SelecedIndexChanged event of the DropDownList control will not fired.
Only when I select a entry in the dropdown box the event will be fired.
For example I enter "Germany", one item matches and the dropdownbox closing. The SelectedIndexChanged event will not fired. It will be fired after leaving the control by tab key or click another control like a button.
When I enter "Germ" two items matches. When I select one the dropdown closing and the SelectedIndexChanged event will be fired.
Why the SelectedIndexChanged event will not fired? It have to fire or not? How to solve?
Here is my code:
public
partial
class
EulaViewerView : UserControl
{
#region private Members
/// <summary>
/// The BackgroundWorker that is used to load the country list asynchronous.
/// </summary>
private
BackgroundWorker _asyncWorker;
#endregion
#region Constructor
/// <summary>
/// The constructor of the class.
/// </summary>
public
EulaViewerView()
{
InitializeComponent();
this
.Localize();
CountrySelector.DropDownListElement.AutoCompleteSuggest.DropDownList.VisualItemFormatting += DropDownList_VisualItemFormatting;
this
.InitializeControl();
}
#endregion
#region BackgroundWorker methods
/// <summary>
/// BackgroundWorker finished event handling.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
asyncWorker_RunWorkerCompleted(
object
sender, RunWorkerCompletedEventArgs e)
{
this
.Cursor = Cursors.Hand;
}
/// <summary>
/// Adding in background created DropDownList items to the DropDonwList.
/// </summary>
/// <param name="sender">The instance of the BackgroundWorker.</param>
/// <param name="e">The BackgroundWorker event arguments.</param>
private
void
asyncWorker_ProgressChanged(
object
sender, ProgressChangedEventArgs e)
{
if
(e.UserState
is
RadListDataItem)
this
.CountrySelector.Items.Add(e.UserState
as
RadListDataItem);
}
/// <summary>
/// Loads the country list and create DropDownList items
/// </summary>
/// <param name="sender">The instance of the BackgroundWorker.</param>
/// <param name="e">The BackgroundWorker event arguments.</param>
private
void
asyncWorker_DoWork(
object
sender, DoWorkEventArgs e)
{
CountryList countyList =
new
CountryList();
BackgroundWorker worker = sender
as
BackgroundWorker;
foreach
(Country country
in
countyList.Countries)
{
if
(country.CountryName !=
""
)
{
string
imagekey =
this
.GetImageKey(country);
if
(!
string
.IsNullOrEmpty(imagekey))
{
RadListDataItem item =
new
RadListDataItem(country.CountryName);
item.Image =
this
.imageList1.Images[
this
.GetImageKey(country)];
item.Value = country;
item.ForeColor = Color.Black;
if
(EulaInfo.Instance.CountrySelected && country.CountryName == EulaInfo.Instance.SelectedCountry.CountryName)
item.Selected =
true
;
worker.ReportProgress(1, item);
}
}
}
}
#endregion
#region helper methods
/// <summary>
/// Formatting event handling for DropDownListItems to add country flag in autocomplete list.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The arguments.</param>
private
void
DropDownList_VisualItemFormatting(
object
sender, VisualItemFormattingEventArgs args)
{
args.VisualItem.Image =
this
.imageList1.Images[
this
.GetImageKey((Country)args.VisualItem.Data.Value)];
}
/// <summary>
/// Inits the control components and starts loading the countries in background.
/// </summary>
private
void
InitializeControl()
{
this
.Cursor = Cursors.WaitCursor;
this
.CountrySelector.DropDownListElement.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains;
this
.CountrySelector.DropDownListElement.TextBox.StretchVertically =
true
;
_asyncWorker =
new
BackgroundWorker();
_asyncWorker.DoWork += asyncWorker_DoWork;
_asyncWorker.ProgressChanged += asyncWorker_ProgressChanged;
_asyncWorker.RunWorkerCompleted += asyncWorker_RunWorkerCompleted;
_asyncWorker.WorkerReportsProgress =
true
;
_asyncWorker.RunWorkerAsync();
}
/// <summary>
/// Gets the image key for the given country in imageList1.
/// </summary>
/// <param name="country"></param>
/// <returns></returns>
private
string
GetImageKey(Country country)
{
string
retval =
string
.Empty;
if
(!
string
.IsNullOrEmpty(country.EnglishName))
retval =
"flag_"
+ country.EnglishName +
".png"
;
return
retval;
}
#endregion
#region Control event handling methods
/// <summary>
/// Syncronize relevant control states to EulaInfo instance.
/// </summary>
/// <param name="sender">The control instance.</param>
/// <param name="e">The event arguments.</param>
private
void
AgreeEulaActor_CheckedChanged(
object
sender, EventArgs e)
{
EulaInfo.Instance.Accepted =
this
.AgreeEulaActor.Checked;
}
/// <summary>
/// Syncronize relevant control states to EulaInfo instance.
/// </summary>
/// <param name="sender">The control instance.</param>
/// <param name="e">The event arguments.</param>
private
void
DisagreeEulaActor_CheckedChanged(
object
sender, EventArgs e)
{
EulaInfo.Instance.Accepted =
this
.AgreeEulaActor.Checked;
}
/// <summary>
/// Print out the actually shown eula.
/// </summary>
/// <param name="sender">The control instance.</param>
/// <param name="e">The event arguments.</param>
private
void
btnPrintActor_Click(
object
sender, EventArgs e)
{
this
.EulaReader.Print();
}
/// <summary>
/// Change DropDownList style and loads the embedded eula document for the selected country into the PDF reader control.
/// </summary>
/// <param name="sender">The DropDownList instance.</param>
/// <param name="e">The event arguments.</param>
private
void
CountrySelector_SelectedIndexChanged(
object
sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
this
.Cursor = Cursors.WaitCursor;
EulaInfo.Instance.SelectedCountry =
this
.CountrySelector.SelectedValue
as
Country;
this
.CountrySelector.DropDownListElement.ShowImageInEditorArea =
true
;
this
.CountrySelector.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
try
{
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
"SharePointProductInstaller.Eula."
+ EulaInfo.Instance.SelectedCountry.EulaID);
this
.EulaReader.LoadDocument(stream);
this
.AgreeEulaActor.Checked = EulaInfo.Instance.Accepted;
this
.DisagreeEulaActor.Checked = !EulaInfo.Instance.Accepted;
this
.btnPrintActor.Enabled =
true
;
this
.AgreeEulaActor.Enabled =
true
;
this
.DisagreeEulaActor.Enabled =
true
;
}
catch
(Exception ex)
{
//throw ex;
}
finally
{
this
.Cursor = Cursors.Default;
}
}
/// <summary>
/// Changes the DropDonwList style for text input (autocomplete mode).
/// </summary>
/// <param name="sender">The DropDownList instance.</param>
/// <param name="e">The event arguments.</param>
private
void
CountrySelector_MouseClick(
object
sender, MouseEventArgs e)
{
this
.CountrySelector.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
this
.CountrySelector.DropDownListElement.ShowImageInEditorArea =
false
;
}
/// <summary>
/// Checks and update DropDownList selected item when leaving.
/// This is needed if control lost focus and no item was selected after entering text.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
CountrySelector_Leave(
object
sender, EventArgs e)
{
if
(
this
.CountrySelector.SelectedValue !=
null
&&
this
.CountrySelector.Text != ((Country)
this
.CountrySelector.SelectedValue).CountryName)
{
var matchedItem =
this
.CountrySelector.Items.First(x => x.Text ==
this
.CountrySelector.Text);
if
(matchedItem !=
null
)
matchedItem.Selected =
true
;
else
{
this
.CountrySelector.Text =
""
;
this
.CountrySelector.SelectedItem =
null
;
}
}
}
private
void
Localize()
{
this
.lCountryInfoHeadline.Text = Properties.Resources.EulaStepTitle;
this
.CountrySelector.NullText = Properties.Resources.CountrySelectorNullText;
this
.DisagreeEulaActor.Text = Properties.Resources.DisagreeEulaActorText;
this
.AgreeEulaActor.Text = Properties.Resources.AgreeEulaActorText;
this
.btnPrintActor.Text = Properties.Resources.btnPrintActorText;
}
#endregion
}
Regards,
Ralf