Please help with my query.

I have created a usercontrol that has a datagridview. The datagridview has a number of textbox and checkbox columns.

The user control had been placed on a form. In the form constructor I add 15 rows to to the datagridview.

On a button click event from a different form, the rows of the datagridview are populated.

Is it possible to to suppress the display of the checkboxes for all rows, where no data has been provided

Thanks,



Re: Windows Forms General Datagridview checkbox column

Keith M. Dennis

I believe the checkboxes must appear in the datagridview even for null values. However, this does not mean the cell value itself must be true or false (it could be null); Perhaps you could change the formatting of cells with null values to indicate this

Keith.




Re: Windows Forms General Datagridview checkbox column

Please help with my query.

Hi Keith,

Will have a look at this later today. Thanks for the suggestion.

Regards.





Re: Windows Forms General Datagridview checkbox column

decyclone

If you display nothing in the checkboxcolumn, when the value is null, then the user won't be able to change the value to true or false if there is no checkbox to click. I think you should override the cell's paint event and give it some background color if the value is null.





Re: Windows Forms General Datagridview checkbox column

Please help with my query.

Jay,

In essence this is what is happening, the rows are being added initally, without any data populating the row. Visually the checkboxes appear in each row for the entire column, and even if I apply a style to the cell when the value is null the outline of the checkbox is still visible.





Re: Windows Forms General Datagridview checkbox column

decyclone

So, are you showing data in readonly mode or can not add new rows And what behavior do you want for check box column when value is null





Re: Windows Forms General Datagridview checkbox column

Please help with my query.

Jay,

No, the user will not be able to add additional new rows, but will be able to update the cells in the existing 15 rows with data. Therefore what I am trying to achieve, is that when the form is first displayed, the rows will be blank as no data has been supplied, therefore I do not want to see the checkbox control, in otherwords the cell should appear to be blank.

Regards





Re: Windows Forms General Datagridview checkbox column

decyclone

Please help with my query. wrote:

Jay,

No, the user will not be able to add additional new rows, but will be able to update the cells in the existing 15 rows with data. Therefore what I am trying to achieve, is that when the form is first displayed, the rows will be blank as no data has been supplied, therefore I do not want to see the checkbox control, in otherwords the cell should appear to be blank.

Regards



Hi 'Please help with my query',

At first it seems reasonable what you are asking. But as i said earlier, the grid can not hide the checkboxes in the empty rows, even if they contain null values. If the checkboxes are not displayed, the user can not provide input, and so, can not change the data in row. If you are talking about the blank last row that always appears by default containing no data, you can disable it by setting 'AllowUsersToAddRows' to false. In other rows the checkboxes can not be hidden. To do that, you need to override the painting, or formatting or whatever behavior DataGridView offers.

I hope this clarifies the problem.

If I am getting your problem wrong, supply some sample code where you are facing problem.





Re: Windows Forms General Datagridview checkbox column

Please help with my query.

Jay,

Thanks, came to the same conclusion.