Using datagridview with imagelist to implement image Columns

Source: Internet
Author: User
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

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.