Achieves effects similar to those in AutoCAD or photoshop. Layer name, layer status, locked, displayed.
Summary: 1. Code Add columns. The order is from right to left, that is, the columns that are added first, and the closer to right. 2. Add rows in the code, Add rows first, and then add data to the row. Datagridview1.rows. add (3); datagridview1.rows [0]. cells [0]. value = "layer 1"; 3. use datagridviewimagecolumn4for the image column. Remove the row title: Maid = false; 5. listview can also achieve the same effect, but the interface is not easy to control. ListBox can be edited, but image Columns cannot be added. C # click to edit the winform control ListBox (with source code)
Code:UsingSystem;
UsingSystem. Collections. Generic;
UsingSystem. componentmodel;
UsingSystem. Data;
UsingSystem. drawing;
UsingSystem. LINQ;
UsingSystem. text;
UsingSystem. Windows. forms;
Namespace Windatagridview
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Private Void Binddata ()
{
// Remove row title
Datagridview1.rowheadersvisible = False ;
// Image column. columns are added from right to left.
// Locked?
Datagridviewimagecolumn collock = New Datagridviewimagecolumn ();
Collock. Name = " Layerlock " ;
Collock. headertext = " Lock " ;
Collock. Width = 20 ;
Datagridview1.columns. insert ( 0 , Collock );
// Show?
Datagridviewimagecolumn colshow = New Datagridviewimagecolumn ();
Colshow. Name = " Layershow " ;
Colshow. headertext = " Display " ;
Colshow. Width = 20 ;
Datagridview1.columns. insert ( 0 , Colshow );
// Edit Box Column
Datagridviewtextboxcolumn coltxt = New Datagridviewtextboxcolumn ();
Coltxt. Name = " Layername " ;
Coltxt. headertext = " Layer name " ;
Datagridview1.columns. insert ( 0 , Coltxt );
// Add row data
Datagridview1.rows. Add ( 3 );
This . Datagridview1.rows [ 0 ]. Cells [ 0 ]. Value = " Layer 1 " ;
This . Datagridview1.rows [ 0 ]. Cells [ 1 ]. Value = Imagelist1.images [ 0 ];
This . Datagridview1.rows [ 0 ]. Cells [ 2 ]. Value = Imagelist1.images [ 2 ];
This . Datagridview1.rows [ 1 ]. Cells [ 0 ]. Value = " Layer 2 " ;
This . Datagridview1.rows [ 1 ]. Cells [ 1 ]. Value = Imagelist1.images [ 0 ];
This . Datagridview1.rows [ 1 ]. Cells [ 2 ]. Value = Imagelist1.images [ 3 ];
This . Datagridview1.rows [ 2 ]. Cells [ 0 ]. Value = " Layer 3 " ;
This . Datagridview1.rows [ 2 ]. Cells [ 1 ]. Value = Imagelist1.images [ 1 ];
This . Datagridview1.rows [ 2 ]. Cells [ 2 ]. Value = Imagelist1.images [ 2 ];
This . Datagridview1.rows [ 3 ]. Cells [ 0 ]. Value = " Layer 4 " ;
This . Datagridview1.rows [ 3 ]. Cells [ 1 ]. Value = Imagelist1.images [ 1 ];
This . Datagridview1.rows [ 3 ]. Cells [ 2 ]. Value = Imagelist1.images [ 3 ];
}
private void form1_load ( Object sender, eventargs e)
{< br> binddata ();
}< BR >} Source: http://files.cnblogs.com/greatverve/WinDataGridView.rar