Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / June 2008

Tip: Looking for answers? Try searching our database.

overriding the leave and Keyup events in custom combo

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert Smith - 30 Jun 2008 23:27 GMT
Hi,
  I have created a custom combo box control that autocompletes entries with
the code as shown below:

However I wish to override the Leave and KeyUp events of the combobox, so
that I can change them so that they call autocompletecombo_keyup and
autocompleteCombo_Leave.

It won't let me override the leave and combo events because the are in the
base
control object not in the combobox object. Is there anyway that I can get
the new Leave and KeyUp events to be embedded within my custom control rather
than the user having to add code to these events to call the new methods.

Thanx in advance
Robert

public partial class AutoCompleteCbo : ComboBox
   {
     

       public AutoCompleteCbo()
       {
           InitializeComponent();
           
       }

       public void AutoCompleteCombo_Leave(ComboBox cbo)
       {
           int iFoundIndex;

           iFoundIndex = cbo.FindStringExact(cbo.Text);

           cbo.SelectedIndex = iFoundIndex;

       }

       public void AutoCompleteCombo_KeyUp(ComboBox cbo, KeyEventArgs e)
       {
           string sTypedText;
           int iFoundIndex;
           object oFoundItem;
           string sFoundText;
           string sAppendText;

           //Allow select keys without Autocompleting

           switch (e.KeyCode)
           {
               case Keys.Back:
               case Keys.Left:
               case Keys.Right:
               case Keys.Up:
               case Keys.Delete:
               case Keys.Down:
                   return;
           }

           //Get the Typed Text and Find it in the list
           sTypedText = cbo.Text;
           iFoundIndex = cbo.FindString(sTypedText);

           //If we found the Typed Text in the list then Autocomplete
           if (iFoundIndex >= 0)
           {

               //'Get the Item from the list (Return Type depends if
Datasource was bound
               //   ' or List Created)
               oFoundItem = cbo.Items[iFoundIndex];

               //'Use the ListControl.GetItemText to resolve the Name in
case the Combo
               //' was Data bound
               sFoundText = cbo.GetItemText(oFoundItem);

               //'Append then found text to the typed text to preserve case
               sAppendText = sFoundText.Substring(sTypedText.Length);
               cbo.Text = sTypedText + sAppendText;

               //'Select the Appended Text
               cbo.SelectionStart = sTypedText.Length;
               cbo.SelectionLength = sAppendText.Length;
           }

       }
   }
Jack Jackson - 01 Jul 2008 00:00 GMT
>Hi,
>   I have created a custom combo box control that autocompletes entries with
[quoted text clipped - 12 lines]
>Thanx in advance
>Robert

Override the OnLeave and OnKeyup methods.

Most .NET classes that raise events have protected methods called
Onxxx whose sole purpose is to raise the event.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.