简体   繁体   中英

How to create a CheckedListBox column for a DataGridView

What is the easiest way to create a DataGridView column that contains a CheckedListBox control for each cell? The CheckedListBox does not need to be databound.

For winforms, in the past I think I used to do it this way:

Either, edit columns for the grid view and add a checkbox column or you can go into the designer of the form and put the following:

private System.Windows.Forms.DataGridViewCheckBoxColumn Column1;//Where column1 is the name of the column.

I don't know about the easiest, but you would probably want to create a custom object that inherits from DataGridViewCell, and also create a control containing your CheckedListBox. Then override the Paint method inside of your custom object and have it draw in the control containing the CheckedListBox.

Once all of that is done, create a DataGridViewColumn, and set the CellTemplate property to the custom DataGridViewCell object you've created.

Add a Template Column and then Edit templet column from start tag. Drag and drop a checkbox into it. you can remove the lable and text box that is created when a databount is modified to Template.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>                
                <asp:TemplateField>                   
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>                
            </Columns>
        </asp:GridView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM