rkf Posted February 27, 2004 Posted February 27, 2004 Anyone know how I can do this in c#??? Thanks. Quote
kahlua001 Posted February 27, 2004 Posted February 27, 2004 From a datareader.. myDropDownList.DataSource = mydatareader; myDropDownList.DataTextField ="DataName" myDropDownList.DataValueField = "DataValue"; myDropDownList.Databind(): Quote
Administrators PlausiblyDamp Posted February 28, 2004 Administrators Posted February 28, 2004 try [DefaultProperty("AutoCompleteEnabled"), DefaultEvent("SelectedIndexChanged")] public class AutoCompleteComboBox : ComboBox { /// /// Event raised if a match isn't found and /// is set to true /// public event CancelEventHandler MatchNotFound; /// /// Internal value to track if we should bother auto completing or not /// private bool _AutoCompleteEnabled = true; /// /// Internal value to track if we should limit to list or not. /// private bool _LimitToList = true; /// /// Enable or disable autocomplete /// [system.ComponentModel.Category("Behavior"), System.ComponentModel.Description("Enables or disables the autocompletion functionality")] public virtual bool AutoCompleteEnabled { get {return _AutoCompleteEnabled;} set {_AutoCompleteEnabled = value;} } protected override void OnValidating(CancelEventArgs e) { if (LimitToList) { int i = this.FindStringExact(Text); if (i == -1) { OnNotInList(e); } else { SelectedIndex = i; } } base.OnValidating(e); } [Category("Behavior"), System.ComponentModel.Description("Limits the selection to items in the list.")] public bool LimitToList { get { return _LimitToList; } set { _LimitToList = value; } } protected virtual void OnNotInList(CancelEventArgs e) { if (MatchNotFound != null) { MatchNotFound(this, e); } } protected override void OnKeyPress(KeyPressEventArgs e) { string currentText = Text; int i; if (e.KeyChar == Convert.ToChar(Keys.Back) ) { if(Text.Length == 0) {return;} //Don't backspace when nothing there Text = Text.Substring(0, SelectionStart - 1); currentText = Text; SelectionStart=Text.Length; } i = FindString(currentText); if( i >= 0 ) { SelectedIndex = i; Select (currentText.Length, Text.Length); } base.OnKeyPress (e); } } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rkf Posted March 3, 2004 Author Posted March 3, 2004 Thanks for the help. I tried this but I get errors because there is no ComboBox... do I have to include a certain library? Wouldn't you want to inherit from a DropDownList for this instead? Thanks. Quote
Administrators PlausiblyDamp Posted March 3, 2004 Administrators Posted March 3, 2004 Whoops the one I posted would only work for a windows app - the older article you refered to in your PM was also for a windows control - I didn't look at the forum before I posted :-\ To do this in a web browser would probably require some client side javascript to work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
foz Posted March 3, 2004 Posted March 3, 2004 when i'm filling a ddl it's usually as follows: ListItem litemp; while(sqlDR.Read()){ string strText, strValue; // set the strings to whatever litemp = new ListItem(strText, strValue); ddlDropdownlist.Items.Add(litemp); } Quote brown m+m, green m+m, it all comes out the same in the end
rkf Posted March 3, 2004 Author Posted March 3, 2004 Sorry, I should re-ohrase my question. I didn't mean filling a dropdown list with database entries - I use a databind for that... I would like to have a dropdownlist that the user can type into and instead of going to the entry of the first letter match, it would try to match the string the user is typing...flike the FAT client drop down. Does anyone know where the code is for the ASP.NET dropdownlist to select the item with the same first letter? Maybe I could just alter that. Quote
rkf Posted March 3, 2004 Author Posted March 3, 2004 Whoops the one I posted would only work for a windows app - the older article you refered to in your PM was also for a windows control - I didn't look at the forum before I posted :-\ To do this in a web browser would probably require some client side javascript to work. Sorry - my bad! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.