Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AutoCompleteCustomSource and appending values
Message
De
24/05/2007 02:12:51
 
 
À
23/05/2007 12:31:45
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01227568
Message ID:
01228155
Vues:
19
Thanks Bonnie,

I'll use your SendKeys workaround and wait till Microsoft fixes it <s>

>Nope, no bug (on your part anyway) ... it happens to me too if I used your code to add to the CustomSource in the Validated event handler. Very strange. It may be a .NET bug though. <g>
>
>I found a simple workaround ... whether it's a good idea to do this or not, I'm not sure, but it works. In your set, I added a SendKeys statement:
>
>
>	if (CustomSourceCourseDescription.IndexOf(value) == -1)
>		{ CustomSourceCourseDescription.Add(value); SendKeys.Send("{TAB}"); }
>
>
>There may be other ways to handle this, but this was the first thing I tried ... I wanted you to know that it seems to be "normal" behavior, nothing you did wrong.
>
>~~Bonnie
>
>
>
>>This is what I've thought too - maybe I have a (small) bug somewhere.
>>Here's my code:
>>
>>Code inside the textbox's Validated event:
>>
>>private void txDescription_Validated(object sender, EventArgs e)
>>{
>>    Program.AddItemToCustomSourceCourseDescription = text.Trim();
>>    this.errorProvider1.Clear();
>>}
>>
>>
>>Code that appends the input to the autocomplete list:
>>
>>private static AutoCompleteStringCollection _customSourceCourseDescription = new AutoCompleteStringCollection();
>>/// <summary>
>>/// AutoCompleteSource for the course descriptions
>>/// </summary>
>>public static AutoCompleteStringCollection CustomSourceCourseDescription
>>{
>>    get
>>    {
>>        return ((Program._customSourceCourseDescription == null) ? new AutoCompleteStringCollection() :
>>            Program._customSourceCourseDescription);
>>    }
>>}
>>
>>/// <summary>
>>/// Adds a new item / string to the AutoCompleteSource for the course descriptions
>>/// </summary>
>>public static string AddItemToCustomSourceCourseDescription
>>{
>>    set
>>    {
>>        if (!string.IsNullOrEmpty(value))
>>        {
>>            if (Program.CustomSourceCourseDescription.IndexOf(value) == -1)
>>            { Program.CustomSourceCourseDescription.Add(value); }
>>        }
>>    }
>>}
>>
>>
>>Can anybody see what I've done wrong?
>>
>>>With both the Leave and the Validated events, your TextBox should not remain in focus. I've only done a little with this (just to see how it works), so I haven't actually updated the AutoCompleteStringCollection, but it still should not cause the TextBox to not lose focus.
>>>
>>>Could you post the code you have in the Leave and/or Validated events?
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>Hi all!
>>>>
>>>>I have the need to use the textbox's AutoCompleteCustomSource property and adding values at runtime doesn't work as expected.
>>>>
>>>>I have a static method (type AutoCompleteStringCollection) which gets fill with data from a DB at the start of the app, at shutdown these values will be written back to the DB. The textbox uses these values for autocompletion - so far so good.
>>>>
>>>>Newly entered values in the textbox should be saved to the AutoCompleteCustomSource and AFAIK this has to be done manually. Which one is the right event to use? Leave, Validated, TextChanged, ...?
>>>>
>>>>Leave and Validated do execute my update routine but the focus remains on the textbox.
>>>>TextChanged causes troubles due to memory read / write and it updates the list with every single character - no good idea.
>>>>
>>>>Any suggestions?
>>>>
>>>>TIA
robert.oh.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform