简体   繁体   中英

Make cells visible DataGridView WinForms C#

Is there any way to make some cells invisible in a DataGridView ?

Basically I am making an invoice application in which certain cells have no meaning when a particular setting is used. I have currently made those cells ReadOnly with no value but it will be cool if they could become invisible/transparent.

Any free 3rd party Control will also do !

At first, I don't think such thing is possible, you can make row or columns invisible. The Visible property for cell is readonly and can't be changed in DataGridView, but a guy here points out to a custom implementation shown here (no source code provided), essentially what he does is disable the cell and override the OnPaint method of DataGridViewCell.

Akshay, think a moment, what does it mean to hide a cell in a grid/table?

you "could" add a whole row or column eventually, a bit like excel allows you to do, but a single cell, what is the expected behaviour?

having a cell set as invisible will still render a rectangle in that location, white over white or black over whatever other combination of back/fore ground colors, you will still see at least a "hole" in the grid.

I don't know a specific way to do it with any grid, setting the cell as read only and clearing the content should help enough, if you really need other things eventually your grid is not well thought for the use you are doing of it, aka should have less rows or columns or should be changed in having multiple smaller grids in the page.

I would suggest making the forecolor be the same as the background color and don't forget the selectionforecolor to be the same as the selectionbackcolor for each of these cells you wish to hide.

So:

MyGrid.rows(0).cells(0).Style.ForeColor = MyGrid.rows(0).cells(0).Style.BackColor
MyGrid.rows(0).cells(0).Style.SelectionForeColor = MyGrid.rows(0).cells(0).Style.SelectionBackColor

I don't think this is possible.

I don't know what you've tried already, have a look through http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.aspx and see if any of the properties could be used as a workaround, particularly the Style property.

Have a look through, http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle.aspx . Is setting the font color to the same value as the background good enough?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM