你去看一看!!
http://dotnet.aspx.cc/

解决方案 »

  1.   

    可以参考下面!自定义一个TableStyles就好了!Dim NewsInfo As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(GetNewCollection)
            Dim ds As DataSet = New DataSet
            NewsInfo.Fill(ds, "NewsInfo")
            Dim tc As DataColumn = New DataColumn("Select", System.Type.GetType("System.Boolean"))
            tc.DefaultValue = False
            tc.AllowDBNull = False
            ds.Tables("NewsInfo").Columns.Add(tc)
            ds.Tables("NewsInfo").DefaultView.AllowNew = False        Dim tcId As DataColumn = New DataColumn("id")        ds.Tables("NewsInfo").Columns.Add(tcId)        Dim tcPostNum As DataColumn = New DataColumn("PostNum")        ds.Tables("NewsInfo").Columns.Add(tcPostNum)        Dim tcState As DataColumn = New DataColumn("tcState")        ds.Tables("NewsInfo").Columns.Add(tcState)
            Dim i = 0
            For Each dr As DataRow In ds.Tables("NewsInfo").Rows
                i += 1            dr("Id") = i
                dr("tcState") = ""
                dr("PostNum") = 0        Next
            NewInfoViewer.DataSource = ds.Tables(0)
            AddCustomDataTableStyle()
            NewInfoViewer.Refresh()        PostNews.DataSource = ds.Tables(0)
            AddPostNewsDataTableStyle()
            PostNews.Refresh()        '===========================================
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Me.Close()        End Try
        End Sub
        Private Sub AddCustomDataTableStyle()        Dim ts1 As New DataGridTableStyle
            ts1.MappingName = "NewsInfo"        Dim boolCol As New DataGridBoolColumn
            boolCol.MappingName = "Select"
            boolCol.HeaderText = "选择"
            boolCol.Width = NewInfoViewer.Width * 0.1
            ts1.GridColumnStyles.Add(boolCol)        Dim TextColId As New DataGridTextBoxColumn
            TextColId.MappingName = "id"
            TextColId.ReadOnly = True        TextColId.HeaderText = "编号"
            TextColId.Width = NewInfoViewer.Width * 0.1
            ts1.GridColumnStyles.Add(TextColId)
            Dim TextColType As New DataGridTextBoxColumn
            TextColType.MappingName = "type"
            TextColType.ReadOnly = True        TextColType.HeaderText = "新闻类别"
            TextColType.Width = NewInfoViewer.Width * 0.3
            ts1.GridColumnStyles.Add(TextColType)
            Dim TextColNum As New DataGridTextBoxColumn
            TextColNum.MappingName = "num"
            TextColNum.ReadOnly = True        TextColNum.HeaderText = "新闻数量"
            TextColNum.Width = NewInfoViewer.Width * 0.2
            ts1.GridColumnStyles.Add(TextColNum)
            Dim TextState As New DataGridTextBoxColumn
            TextState.MappingName = "tcState"
            TextState.ReadOnly = True        TextState.HeaderText = "当前状态"
            TextState.Width = NewInfoViewer.Width * 0.2
            ts1.GridColumnStyles.Add(TextState)
            ts1.AllowSorting = False        NewInfoViewer.TableStyles.Add(ts1)    End Sub
        Private Sub AddPostNewsDataTableStyle()        Dim ts1 As New DataGridTableStyle
            ts1.MappingName = "NewsInfo"           Dim TextColId As New DataGridTextBoxColumn
            TextColId.MappingName = "id"
            TextColId.ReadOnly = True        TextColId.HeaderText = "编号"
            TextColId.Width = NewInfoViewer.Width * 0.1
            ts1.GridColumnStyles.Add(TextColId)
            Dim TextColType As New DataGridTextBoxColumn
            TextColType.MappingName = "type"
            TextColType.ReadOnly = True        TextColType.HeaderText = "新闻类别"
            TextColType.Width = NewInfoViewer.Width * 0.3
            ts1.GridColumnStyles.Add(TextColType)
            TextColType.ReadOnly = True
            Dim TextColNum As New DataGridTextBoxColumn
            TextColNum.MappingName = "num"
            TextColNum.ReadOnly = True        TextColNum.HeaderText = "库存新闻数量"
            TextColNum.Width = NewInfoViewer.Width * 0.2
            ts1.GridColumnStyles.Add(TextColNum)
            Dim TextState As New DataGridTextBoxColumn
            TextState.MappingName = "PostNum"
            TextState.HeaderText = "要发帖数量"
            TextState.Width = NewInfoViewer.Width * 0.3
            ts1.GridColumnStyles.Add(TextState)
            TextState.ReadOnly = False        ts1.AllowSorting = False        PostNews.TableStyles.Add(ts1)    End Sub
      

  2.   


    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
      

  3.   

    晕,自己回答
    private void Collate_Load(object sender, System.EventArgs e)
    {
    this.radioMoney.Checked = true;
    string query_sql = "select id,AccDate,AccName,AccNo,No,Abr_AccId,Abr_Content,Abr_Person,StartAmt,DbtAmt,CrdAmt,EndAmt,AccFlag from accounttype";
    DataAccess data = new DataAccess();
    DataTable tb = data.GetDataTable(query_sql);
    dataGridView.DataSource = tb; DataGridTableStyle ts = new DataGridTableStyle();
    DataGridTableStyle tsbool = new DataGridTableStyle();
    ts.MappingName = tb.TableName;
    dataGridView.CaptionText = "对帐查询";

    for(int i = 0;i<tb.Columns.Count;i++)
    {
    DataGridTextBoxColumn ColText = new DataGridTextBoxColumn();
    if(i != 12)
    {
    //设置DataGrid列标题
    ColText.HeaderText = ConvertTitle(tb.Columns[i].ColumnName);
    ColText.MappingName = tb.Columns[i].ColumnName;
    ColText.ReadOnly = true;
    }
    else if(i == 12)
    {
    //加载CheckBox列
    ColBool.HeaderText = ConvertTitle(tb.Columns[i].ColumnName);
    ColBool.MappingName = tb.Columns[i].ColumnName;
    ColText.ReadOnly = false;
    ts.GridColumnStyles.Add(ColBool);
    } ts.PreferredColumnWidth = 85;
    ts.PreferredRowHeight = 15;
    ts.GridColumnStyles.Add(ColText);
    }
    dataGridView.TableStyles.Clear();
    dataGridView.TableStyles.Add(tsbool);
    dataGridView.TableStyles.Add(ts);
    }
    绑定CheckBox到DataGrid第12列 
    /// <summary>
    /// 将数据库中的字段名替换为中文名称
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    private string ConvertTitle(string name)
    {
    switch (name)
    {
    case "id":
    return "编号";
    case "AccDate":
    return "日期";
    case "AccName":
    return "帐户名称";
    case "AccNo":
    return "帐号";
    case "No":
    return "凭证号";
    case "Abr_AccId":
    return "支票号";
    case "Abr_Content":
    return "内容";
    case "Abr_Person":
    return "报销人";
    case "StartAmt":
    return "期初余额";
    case "DbtAmt":
    return "借方";
    case "CrdAmt":
    return "贷方";
    case "EndAmt":
    return "余额";
    case "AccFlag":
    return "是否对帐";
    default:
    return "";
    }
    }
    对CheckBox进行操作
    /// <summary>
    /// 对DataGrid中的CheckBox进行值判断,并对数据库做出修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void dataSource_CurrentCellChanged(object sender, System.EventArgs e)
    {
    try
    {
    string temp = dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),0].ToString();
    DataAccess data = new DataAccess();
    //判断是否点中的是CheckBox列,以保证其值正确更改
    if(dataGridView.CurrentCell.ColumnNumber == 12)
    {
    //判断CheckBox单元格的值,并根据其值更新数据库
    if(dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12].ToString() == "False")
    {
    dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12] = true;
    string query_sql = "update accounttype set accflag = '1' where id = '" + temp + "'";
    data.ExecuteSQL(query_sql);
    }
    else if(dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12].ToString() == "True")
    {
    dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12] = false;
    string query_sql = "update accounttype set accflag = '0' where id = '" + temp + "'";
    data.ExecuteSQL(query_sql);
    }
    }
    else
    {
    //选中的不是CheckBox列就跳出此过程
    return;
    }
    }
    catch
    {
    MessageBox.Show("表格中未有任何记录!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
    } }