可以去查下MSDN,,但是03的好久以前用过。现在都是05了,LZ怎么还在用??

解决方案 »

  1.   

    没办法呀,唉,其实挺不喜欢用.net做winform的
      

  2.   

    1.1的时候DataGrid用DataGridTableStyle来控制模板和样式
    添加一列可以用DataGridTextboxColumn类型,加上只读属性就是你要的label,它的MappingName属性对应到数据列上
    要单元格的事件用currentcellchanged事件private void Form1_Load(object sender, System.EventArgs e)
    {
    RenderGrid();
    this.dataGrid1.DataSource = GetData();


    } private void RenderGrid()
    {
    DataGridTableStyle tableStyle = new DataGridTableStyle(); DataGridTextBoxColumn col = new DataGridTextBoxColumn();
    col.HeaderText = "名称";
    col.MappingName = "Name";
    col.ReadOnly = true; tableStyle.GridColumnStyles.Add(col);
    this.dataGrid1.TableStyles.Add(tableStyle);
    } private object GetData()
    {
    DataTable table = new DataTable();
    DataColumn col = new DataColumn("Name", typeof(string));
    table.Columns.Add(col);

    DataRow row = table.NewRow();
    row[0] = "hello";
    table.Rows.Add(row); row = table.NewRow();
    row[0] = "world";
    table.Rows.Add(row); return table; } private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
    {
    MessageBox.Show(this.dataGrid1[dataGrid1.CurrentCell].ToString());
    }
      

  3.   

    我建议你用 DATALIST
    去绑定
    不要用DATAGRID