Share via


DataGrid.ReadOnly 属性

获取或设置一个指示网格是否处于只读模式的值。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property ReadOnly As Boolean
用法
Dim instance As DataGrid
Dim value As Boolean

value = instance.ReadOnly

instance.ReadOnly = value
public bool ReadOnly { get; set; }
public:
property bool ReadOnly {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_ReadOnly ()

/** @property */
public void set_ReadOnly (boolean value)
public function get ReadOnly () : boolean

public function set ReadOnly (value : boolean)

属性值

如果网格处于只读模式,则为 true;否则为 false。默认为 false

备注

在只读模式中,可以滚动网格,展开或折叠节点,等等。但是,不能进行添加、编辑或删除。

DataGridColumnStyle 还有 ReadOnly 属性,可以针对每一列将该属性设置为真以防止编辑数据。

如果要禁止用户直接在 System.Windows.Forms.DataGrid 中编辑数据,可将 ReadOnly 设置为真。例如,您可能希望允许用户查看表中的所有列,但只允许他们通过另一个窗体上的 TextBox 控件来编辑特定字段。

示例

下面的代码示例切换 ReadOnly 属性。

Private Sub ToggleReadOnly(ByVal myGrid As DataGrid)
    myGrid.ReadOnly = myGrid.ReadOnly Xor True
 End Sub
 

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

DataGrid 类
DataGrid 成员
System.Windows.Forms 命名空间
DataColumn.ReadOnly