-
Aug 30th, 2014, 12:32 AM
#1
Thread Starter
New Member
Unable to edit checkbox column at runtime in datagridview
I have a datagridview with a checkbox column.The datagridview is bound to a datasource through code using the method
datagridview1.datasource=my Dataset.
The problem is while I want the rest of the grid to remain readonly,I want the checkbox column to remain editable.I have tried various methods and events like 'grid MouseDown,MouseClick,CellClick,etc and properties such as editable=true and all that,based on results of internet searches.
A solution would be appreciated.
Another problem is that at the very end of the gridview,there are two columns which I want remain hidden.While I know how to hide a column,despite all my tries,I could not locate the index of these columns.
Also,if a grid is bound through code,how do I center-justify all the cells?
Thanks in advance,
Khalid.
-
Aug 30th, 2014, 05:54 AM
#2
Re: Unable to edit checkbox column at runtime in datagridview
You don't need to handle any events. If you want all the other columns to be read-only then you set the ReadOnly properties of those columns to True, leaving it False for your check box column.
In relation to all your issues, how about you add all the columns in the designer and set the AutoGenerateColumns propert of the grid to False? That way you can configure everything you want in the designer and not have to worry about code. You just set the DataPropertyName of each column to tell it which data source column to bind to.
-
Aug 30th, 2014, 12:00 PM
#3
Thread Starter
New Member
Re: Unable to edit checkbox column at runtime in datagridview
Originally Posted by jmcilhinney
You don't need to handle any events. If you want all the other columns to be read-only then you set the ReadOnly properties of those columns to True, leaving it False for your check box column.
Thanks,I'll try that.
Originally Posted by jmcilhinney
In relation to all your issues, how about you add all the columns in the designer and set the AutoGenerateColumns propert of the grid to False? That way you can configure everything you want in the designer and not have to worry about code. You just set the DataPropertyName of each column to tell it which data source column to bind to.
That is exactly what I had done earlier.I Had designed the DGV in the designer,but later,due to a change in the program configuration,I needed to refresh the DGV repeatedly and apparently that is not easy if the the DGV is bound through the designer.To get around that,I loaded the data in the DGV through code and its almost working like a dream except that now the checkbox column has disappeared.
Due to these developments,I'll need to rephrase my query.Now I have the difficult task of rendering a checkbox column at runtime with all checkboxes checked at start and any checkbox being able to be unchecked at will with a corresponding event being also available.
I know that it is a difficult task but any help will be appreciated.I have explored options on the internet about creating the column at runtime but could not find a viable solution.Maybe the following could be explored,though I find it rather daunting:
http://www.vbforums.com/showthread.p...-column-header
-
Aug 30th, 2014, 08:19 PM
#4
Re: Unable to edit checkbox column at runtime in datagridview
Originally Posted by khldindia
That is exactly what I had done earlier.I Had designed the DGV in the designer,but later,due to a change in the program configuration,I needed to refresh the DGV repeatedly and apparently that is not easy if the the DGV is bound through the designer.
I didn't say anything about binding the grid in the designer. I said that you should add the columns in the designer and tell each one which column of the data source they should bind to. At run time, you set the AutoGenerateColumns property to False and set the DataSource, i.e. bind the data to the grid. For each column in the data source, it will bind to the grid column with the appropriate DataPropertyName or it will not bind at all. That way, there's no need to try to hide any columns you don't want the user to see because they won't be created in the first place.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|