I have a datagridview, and it loads information from db. However, at run time, I want to allow a user to update a cell(which is readonly by default) but I am not able to do this, I need to do this because all the changes are saved in db but if I reload it it, some color style etc will be gone, therefore I want to only reload from db at request and make a change to the text of a read only col, please guide.
Thanks
This is the actual
Questionof the userI have a column in datagridview, which by default(
I dont set it readonly anywhere in code) readonly. It is coming from adataset which gets data from a stored procedure, this particular field is a calculated one,so there is no column in the table for it. All other fields which are in table I can manipulate,except for this one. I need to (for only display purposes in datagridview) change this columns value at run time which is causing a readonly errorThis is the
Answerwhich solved the user issue.After you have read the data from dataset, the column for which it is saying read-only, try doing this –
ds.Tables[0].Columns["Your New Column"].ReadOnly = false;Read the comments below for more clarity please.Ignore the answer & code below because the actual question of the user is in the comments below which I have written above. User should modify his question. Its totally wrong and misleading
Add a Winforms Project, Drop a DataGridView and a Button. Add a click Handler to the Button.
Add a column in DataGridView and name the
DataPropertyof the column as “Name” in the Designer. Mark it asRead-Only. The column DataPropertyName must match with fields in database.I have a class called Books with a Property called Name. Hence it should be calledNamein this case.Copy Paste the code below and Hit F5.
Click the Button to update the read-only column value.DataGridView Designer Code for Reference:-