'DataGridView column bound to a read-only field must have ReadOnly set to True
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:
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.
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
Solution 1:[1]
You can actually set the ReadOnly property for the DataTable column!
Dim dt As DataTable = oDL.GetTheItems()
dt.Columns("Selected").ReadOnly = false
DataGridView1.DataSource = dt
Solution 2:[2]
Have you tried? (setting properties) :
AllowUserToAddRows = False
AllowUserToDeleteRows = False
ReadOnly = True
Solution 3:[3]
First Set DataTable ReadOnly Property False Then Set Gridview ReadOnly Property false
EX- DataTable dt=("Select * prom priceList"); dt.Columns["Rate"].ReadOnly = false;
DataGrid View dgv=.dataSource=dt; dgv.Columns["Rate"].ReadOnly = false;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | C.B. |
| Solution 2 | Haris |
| Solution 3 |
