ListView controls in C # join ComboBox

Source: Internet
Author: User

Many projects use the ListView control to render and edit data. To facilitate user input, you can add ComboBox to the ListView control to improve user operability. Implementation of the effect diagram:

1. Create a user control, name Mylistview, and inherit from the ListView control.

Post the code directly:

using System;


using System.Collections;


using System.ComponentModel;


using System.Drawing;


using System.Data;


using System.Windows.Forms;





namespace Inheritedlistview


{


///<summary>


///Summary description for UserControl1.


///</summary>


public class MyListView:System.Windows.Forms.ListView


  {


///<summary>


///Required designer variable.


///</summary>


private System.ComponentModel.Container components = null;





Public Mylistview ()


    {


//This is required by the windows.forms Form Designer.


InitializeComponent ();





//Todo:add any initialization on the initform call


    }





///<summary>


///clean up any being used.


///</summary>


protected override void Dispose (bool disposing)


    {


if (disposing)


      {


if (components!= null)


components. Dispose ();


      }


base. Dispose (disposing);


    }





#region Component Designer generated code


///<summary>


///Required to Designer support-do not modify


The contents is with the Code Editor.


///</summary>


private void InitializeComponent ()


    {


components = new System.ComponentModel.Container ();


    }


#endregion





Private Const int wm_hscroll = 0x114;


Private Const int wm_vscroll = 0x115;





protected override void WndProc (ref message msg)


    {


//Look for the Wm_vscroll or the Wm_hscroll messages.


if (msg. MSG = wm_vscroll) | | (Msg. MSG = wm_hscroll)


      {


//Move focus to the ListView to cause ComboBox to lose focus.


this. Focus ();


      }





//Pass message to default handler.


base. WndProc (ref msg);


    }


  }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.