开发者

Make cells visible DataGridView WinForms C#

开发者 https://www.devze.com 2023-03-13 09:07 出处:网络
Is there 开发者_如何学Pythonany 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 u

Is there 开发者_如何学Pythonany 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 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消