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);
}
}
}