如题,谢谢!

解决方案 »

  1.   

    设置datagridview的列的属性,将其选择为可以复选,然后在写单击时间
      

  2.   

    private void AddColumn()
    {
        DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
        {
            column.HeaderText = "a";        column.Name = "a";        column.AutoSizeMode = 
                DataGridViewAutoSizeColumnMode.DisplayedCells;
            column.FlatStyle = FlatStyle.Standard;
            column.ThreeState = true;
            column.CellTemplate = new DataGridViewCheckBoxCell();
            column.CellTemplate.Style.BackColor = Color.Beige;
        }    DataGridView1.Columns.Insert(0, column);
    }
    然后编辑事件处理 
      

  3.   

    http://blog.csdn.net/ykhykh/archive/2006/12/16/1445814.aspx
      

  4.   

    今天晚上先写一段VB的代码吧,lz如果能自己转就更好了,呵呵
    注意:Form上不需要任何控件,全部由程序动态添加Public Class Form1    Private DataGridView1 As New DataGridView
        Private CheckBox1 As New CheckBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AddHandler CheckBox1.CheckedChanged, AddressOf CheckBox1_CheckedChanged
            AddHandler DataGridView1.CellPainting, AddressOf DataGridView1_CellPainting
            Me.DataGridView1.AllowUserToResizeRows = False
            Me.DataGridView1.AllowUserToResizeColumns = False
            Me.DataGridView1.Dock = DockStyle.Fill        Me.DataGridView1.Columns.Add(New DataGridViewCheckBoxColumn)
            Me.DataGridView1.Columns.Add("Column2", "Column2")        For i As Integer = 1 To 3
                Me.DataGridView1.Rows.Add(0, "Row" + i.ToString + " Column2")
            Next        Me.CheckBox1.Visible = False
            Me.CheckBox1.Text = "CheckBox"        Me.Controls.Add(DataGridView1)
            Me.Controls.Add(CheckBox1)
        End Sub    Private Sub CheckBox1_CheckedChanged(ByVal send As Object, ByVal e As System.EventArgs)
            For i As Integer = 0 To Me.DataGridView1.RowCount - 1
                Me.DataGridView1.Rows(i).Cells(0).Value = CheckBox1.Checked
            Next
        End Sub    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
            If e.RowIndex = -1 And e.ColumnIndex = 0 Then
                Dim p As Point = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Location
                p.Offset(Me.DataGridView1.Left, Me.DataGridView1.Top)
                Me.CheckBox1.Location = p
                Me.CheckBox1.Size = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False).Size
                Me.CheckBox1.Visible = True
                Me.CheckBox1.BringToFront()
            End If
        End SubEnd Class
      

  5.   

    LZ着急用,那就贴C#代码如下:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private DataGridView DataGridView1 = new DataGridView();
            private CheckBox CheckBox1 = new CheckBox();         public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                CheckBox1.CheckedChanged += CheckBox1_CheckedChanged;
                DataGridView1.CellPainting += DataGridView1_CellPainting;
                this.DataGridView1.AllowUserToResizeRows = false;
                this.DataGridView1.AllowUserToResizeColumns = false;
                this.DataGridView1.Dock = DockStyle.Fill;            this.DataGridView1.Columns.Add(new DataGridViewCheckBoxColumn());
                this.DataGridView1.Columns.Add("Column2", "Column2");            for (int i = 1; i <= 3; i++)
                {
                    this.DataGridView1.Rows.Add(0, "Row" + i.ToString() + " Column2");
                }            this.CheckBox1.Visible = false;
                this.CheckBox1.Text = "CheckBox";            this.Controls.Add(DataGridView1);
                this.Controls.Add(CheckBox1); 
            }        private void CheckBox1_CheckedChanged(object send, System.EventArgs e)
            {
                for (int i = 0; i <= this.DataGridView1.RowCount - 1; i++)
                {
                    this.DataGridView1.Rows.SharedRow(i).SetValues(CheckBox1.Checked);
                }
            }        private void DataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
            {
                if (e.RowIndex == -1 & e.ColumnIndex == 0)
                {
                    Point p = this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
                    p.Offset(this.DataGridView1.Left, this.DataGridView1.Top);
                    this.CheckBox1.Location = p;
                    this.CheckBox1.Size = this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
                    this.CheckBox1.Visible = true;
                    this.CheckBox1.BringToFront();
                }
            }     }
    }
      

  6.   

    我也是进来学习的。
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/