【问题标题】:Make DataGrid cells readonly将 DataGrid 单元格设为只读
【发布时间】:2012-08-22 01:04:11
【问题描述】:

有 DataGrid (WinForms / .NET CF 3.5) 与 DataSource 绑定以列出对象。 如何禁用单元格中的数据编辑?

【问题讨论】:

    标签: .net windows winforms datagrid compact-framework


    【解决方案1】:

    您可以尝试使用 DataGridView 代替 DataGrid 并将其 EditMode 属性设置为 EditProgrammatically

      dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
    

    【讨论】:

      【解决方案2】:

      试试这个,

      dt.Columns(0).ReadOnly = True '// Make the column(0) readonly and assign to DataGrid.
      
      dataGridView1.DataSource = dt
      

      此代码可以使您设置为只读的任何列。顺便说一句,

      dt

      表示为用于将数据从数据库及其数据源收集到数据网格dataGridView1的数据表。

      【讨论】:

        猜你喜欢
        • 2012-10-19
        • 2011-01-30
        • 2016-07-15
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多