vb.net 绑定到只读字段的 DataGridView 列必须将 ReadOnly 设置为 True
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13932934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DataGridView column bound to a read-only field must have ReadOnly set to True
提问by Rami Atia
I know there must be a simple solution to this question, but I seem to be missing the answer. I have a Visual Studio 2008 Winforms application where I created a datagridview to display data to users. In the datagridview I allow the users to edit information. One of the cells is set to read only and the users want to be able to edit this information now. When I go into the datagridview designer to set the cell to Readonly = False the change does not get saved. Does not matter what I do the change WILL not get saved. I am now looking into changing this at run time using the code below:
我知道这个问题必须有一个简单的解决方案,但我似乎错过了答案。我有一个 Visual Studio 2008 Winforms 应用程序,我在其中创建了一个 datagridview 来向用户显示数据。在 datagridview 中,我允许用户编辑信息。其中一个单元格设置为只读,用户现在希望能够编辑此信息。当我进入 datagridview 设计器将单元格设置为 Readonly = False 时,更改不会被保存。不管我做什么改变都不会被保存。我现在正在考虑使用以下代码在运行时更改它:
When I use that code I get the error mentioned in the title. It seems to me that I am stuck now... I can't change the cell to readonly = false using the Visual Studio designer. I can't set the cell to readonly = false at runtime.
当我使用该代码时,我收到标题中提到的错误。在我看来,我现在卡住了……我无法使用 Visual Studio 设计器将单元格更改为 readonly = false。我无法在运行时将单元格设置为 readonly = false。
Question: What am I doing wrong? Is there something else I can do? This is quite a sizable application for multiple users and this is a request made by most of the users.
问题:我做错了什么?我还能做些什么吗?对于多个用户来说,这是一个相当大的应用程序,这是大多数用户提出的要求。
Any help would be appreciated.
任何帮助,将不胜感激。
Dim oDL As New MTN.BusinessLayer.MasterTables()
Dim dt As DataTable = oDL.GetTheItems() DataGridView1.DataSource = dt
回答by C.B.
You can actually set the ReadOnly property for the DataTable column!
您实际上可以为 DataTable 列设置 ReadOnly 属性!
Dim dt As DataTable = oDL.GetTheItems()
dt.Columns("Selected").ReadOnly = false
DataGridView1.DataSource = dt
回答by sagar jadhav
First Set DataTable ReadOnly Property False Then Set Gridview ReadOnly popety false
首先设置 DataTable ReadOnly 属性为 False 然后设置 Gridview ReadOnly popety false
EX-
前任-
DataTable dt=("Select * prom priceList");
dt.Columns["Rate"].ReadOnly = false;
DataGrid View dgv=.dataSource=dt;
dgv.Columns["Rate"].ReadOnly = false;
回答by Haris
Have you tried? (setting properties) :
你有没有尝试过?(设置属性):
AllowUserToAddRows = False
AllowUserToDeleteRows = False
ReadOnly = True

