windows 控件DataGrid要么全是只读的,要么所有的行都能编辑,能不能实现只让指定的行进行编辑,其他的行都是只读的呢?

解决方案 »

  1.   

    不会吧,DataGrid做得怎么笨啊,DataGrid我得不到行的属性,只能得到单元格的
      

  2.   

    winform里是不怎么好用,通过DataSource来操纵试试
      

  3.   

    不行的,因为只读属性是给Column加的
      

  4.   

    to windows 控件DataGrid要么全是只读的,要么所有的行都能编辑,能不能实现只让指定的行进行编辑,其他的行都是只读的呢?How can I prevent a particular cell from being editable
    http://www.syncfusion.com/faq/windowsforms/Search/758.aspx
      

  5.   

    可以用DataView作为数据源,然后当状态为编辑状态时,锁定鼠标在当前编辑行.
      

  6.   

    1. 把DataGrid 的 ReadOnly 设置成true.
    2. 在需要编辑的时候,把ReadOnly改成false.
    3. 在DataGrid 的 CurrentCell事件中判断是不是在编辑行。如果不是,则将CurrentCell移动回来。
    4. 为了达到3的目的,你需要在2的时候设置一个类级别的成员,记录当前编辑行的行号。
      

  7.   

    可以做到,在要编辑的单元格后面隐藏一个文本框(style自己设置),
    当鼠标进入或者鼠标按下的时候,将单元格的值copy到文本框里,让文本框显示,这时可以编辑,
    更新之后再回到编辑之前的状态!
      

  8.   

    编辑之后需要重新bind一下
      

  9.   

    To ClementDik(剑问天): 在DataGrid 的 CurrentCell事件中判断是不是在编辑行。如果不是,则将CurrentCell移动回来。在哪个事件中怎样把单元格移回来?_CurrentCellChanged(object sender, System.EventArgs e)
      

  10.   

    DataGridTableStyle ts = new DataGridTableStyle();//设置表格模式
    DataGridTextBoxColumn aColumnTextColumn;
    ts.AllowSorting = false;
    ts.AlternatingBackColor = Color.LightGray;      //交替显示
    ts.MappingName = newTable.TableName;
    int numCols = newTable.Columns.Count;
    for (int i = 0;i< numCols;i++)
    {
    aColumnTextColumn = new DataGridTextBoxColumn()
    if( i==0 ) 
    {
    aColumnTextColumn.ReadOnly=true;
    }
    if ( i == 1 )//当鼠标单击列时允许响应
    {
    aColumnTextColumn.TextBox.MouseDown += new MouseEventHandle(TextBoxMouseDownHandler);

    }
    ......
    aColumnTextColumn.MappingName = newTable.Columns[i].ColumnName;
    aColumnTextColumn.HeaderText = newTable.Columns[i].ColumnName;
    aColumnTextColumn.NullText = "";
    aColumnTextColumn.Format = "N"; //设置为数字格式显示
    ts.GridColumnStyles.Add(aColumnTextColumn);
    }
    this.dataGrid1.TableStyles.Add(ts);
      

  11.   

    dgrContect.CurrentCell=new DataGridCell(dsContect.Tables[0].Rows.Count,0);
      

  12.   

    谢谢各位了,呵呵DataGrid做得不好,很多地方和功能都需要进行限制,还得自己写。十分感谢大家的帮助!