Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

Custom ComboBoxes with Advanced Drop-down Features

Rate me:
Please Sign up or sign in to vote.
4.95/5 (55 votes)
22 Apr 2003CPOL4 min read 314K   12.1K   125  
Contains several ComboBoxes which uses Windows themes and contains ComboBoxes with CheckBoxed lists and TreeViews
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;

using UtilityLibrary.Win32;
using UtilityLibrary.General;
using UtilityLibrary.DateTimeControls;


namespace UtilityLibrary.Combos
{
  [ToolboxItem(true)]
  [ToolboxBitmap(typeof(UtilityLibrary.Combos.DateCombo), "UtilityLibrary.Combos.DateCombo.bmp")]
	public class DateCombo : CustomCombo
	{
    #region Class members
    CalendarViewEx m_calendar = new CalendarViewEx();
    #endregion

    #region Class Properties
    [Browsable(false)]
    public CalendarViewEx CalendarDropDown
    {
      get
      {
        return m_calendar;
      }
    }

    new public DateTime Value
    {
      get
      {  
        return m_calendar.Value;
      }
      set
      {
        m_calendar.Value = value;
      }
    }
    #endregion

    #region Class constructor
		public DateCombo()
		{
      m_calendar.DropDownTab = true;
      m_calendar.ValueChanged += new EventHandler( OnCalendarValueChanged );
      base.Value = "None";
		}
    #endregion
    
    #region Class Overrides
    protected override void OnDropDownControlBinding( CustomCombo.EventArgsBindDropDownControl e )
    {
      e.BindedControl = m_calendar;
      
      // in case when we do data load on scroll message then 
      m_ctrlBinded = m_calendar;
      m_bControlBinded = true;
    }

    protected override void OnPrevScrollItems()
    {
      if( m_calendar.Value != DateTime.MinValue )
      {
        base.Value = m_calendar.Value.AddDays(-1).ToShortDateString();
      }
      else
      {
        base.Value = "None";
      }
    }

    protected override void OnNextScrollItems()
    {
      if( m_calendar.Value != DateTime.MinValue )
      {
        base.Value = m_calendar.Value.AddDays(1).ToShortDateString();
      }
      else
      {
        base.Value = "None";
      }
    }

    protected override void OnValueChanged()
    {
      Trace.WriteLine( "OnValueChanged", "method call" );

      if( base.Value == "None" )
      {
        m_calendar.Value = DateTime.MinValue;
      }
      else
      {
        m_calendar.Value = DateTime.Parse( base.Value );
      }

      base.OnValueChanged();
    }

    protected override void OnDropDownSizeChanged()
    {
      if( m_dropDownForm != null )
      {
        m_dropDownForm.Size = new Size( m_calendar.Width, m_calendar.Height );
      }
    }

    protected override void OnDropDownFormLocation()
    {
      Rectangle pos = RectangleToScreen( ClientRectangle );
      m_dropDownForm.Location = new Point( pos.Right - m_dropDownForm.Width, pos.Bottom + 1 );
    }

    protected virtual  void OnCalendarValueChanged( object sender, EventArgs e )
    {
      Trace.WriteLine( "OnCalendarValueChanged", "method call" );

      if( m_calendar.Value == DateTime.MinValue )
      {
        base.Value = "None";
      }
      else
      {
        base.Value = m_calendar.Value.ToShortDateString();
      }
    }
    #endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO ArtfulBits Inc.
Ukraine Ukraine
Name:Kucherenko Oleksandr

Born:September 20, 1979

Platforms: Win32, Linux; - well known and MS-DOS; Win16; OS/2 - old time not touched;

Hardware: IBM PC

Programming Languages: Assembler (for Intel 80386); Borland C/C++; Borland Pascal; Object Pascal; Borland C++Builder; Delphi; Perl; Java; Visual C++; Visual J++; UML; XML/XSL; C#; VB.NET; T-SQL; PL/SQL; and etc.

Development Environments: MS Visual Studio 2001-2008; MS Visual C++; Borland Delphi; Borland C++Builder; C/C++ any; Rational Rose; GDPro; Together and etc.

Libraries: STL, ATL, WTL, MFC, NuMega Driver Works, VCL; .NET 1.0, 1.1, 2.0, 3.5; and etc.

Technologies: Client/Server; COM; DirectX; DirectX Media; BDE; HTML/DHTML; ActiveX; Java Servlets; DCOM; COM+; ADO; CORBA; .NET; Windows Forms; GDI/GDI+; and etc.

Application Skills: Databases - design and maintain, support, programming; GUI Design; System Programming, Security; Business Software Development. Win/Web Services development and etc.

Comments and Discussions