开发者

DataGridView how to display grid lines in entire client area?

开发者 https://www.devze.com 2023-01-04 08:08 出处:网络
Is there a way to turn on grid lines in the entire datagridview client area rather than them becoming visible as you add rows?

Is there a way to turn on grid lines in the entire datagridview client area rather than them becoming visible as you add rows?

I have read the msdn but find nothin开发者_JS百科g of use.

C#, winforms, visual studio 2008

Thanks, R.


You could possibly subclass the DataGridView, override its PaintBackground event and add an image of some lines. See here and here for some examples.

I realise this is a bit of a hack. :)


I'd choose between Andy's proposal, and the virtual mode.

In the virtual mode of grid view you will need to provide an interface to the data store by handling a number of events from the control. In such case you can set a RowCount property directly and then decide in the CellValueNeeded event if the cell contains data or not. You will have to determine though the number of rows that will fill your control. http://msdn.microsoft.com/en-us/library/ms171622.aspx


You could add a heap of dummy rows to the grid and make them read only.


I faced that problem when I had number of rows in my datagrid what was taken from config file. In case of small number of the rows the datagrid looks ugly with gray background color. After discussion we desided to make datagrid height dynamic. That in its turn takes the parent window where the datagrid located to change its height as well. Now it looks pretty fine. This is not right answer to your question but rather consider style issue.


int MAX_ROWS = 10;
int MAX_CELLS = 10;
dataGridView1.ColumnCount = MAX_CELLS;
int currentRowIndex = dataGridView1.Rows.Add(MAX_ROWS);
foreach (DataGridViewRow row in dataGridView1.Rows)
{
    foreach (DataGridViewCell cell in row.Cells)
    {
        cell.ValueType = typeof(String);
        cell.Value = "This is the: " + cell.OwningColumn.Index.ToString() + 
            " " + cell.OwningRow.Index.ToString() + " cell";
    }
}

I know that it's not the best solution but it doesn't require making of a new DataGridView-like custom control with setting it's background image.

0

精彩评论

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