I have tried to make a simple sudoku Interface using dataGridView. The problem is that I can't get DividerHeight to work. The code below is able to change the width of the vertical divider, but not the horizontal divider:
public partial class Form1 : Form
{
private DataTable sudokuTable;
public Form1()
{
InitializeComponent();
sudokuTable = getTable();
dataGridView1.DataSource = sudokuTable;
for (int i = 0; i < 9; i++){
dataGridView1.Columns[i].Width = 25;
}
dataGridView1.Columns[2].DividerWidth = 5; //Working
dataGridView1.Columns[5].DividerWidth = 5; //Working
dataGridView1.Rows[2].DividerHeight = 5; //Not working
dataGridView1.Rows[5].DividerHeight = 5; //Not working
}
private static DataTable getTable()
{
DataTable newDataTable = new DataTable();
for (int i = 0; i < 9; i++)
{
newDataTable.Columns.Add("c" + i+1, typeof(int));
}
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
newDataTable.Rows.Add(1, 2, 3, 4, 5, 6, 7, 8, 9);
return newDataTable;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
Is there some Properties I have to change to make it work?
I have found a link suggesting dividerHeight is not implemented:
http://www.visualwebgui.com/Developers/Forums/tabid/364/forumid/68/threadid/68506/scope/posts/Default.aspx
Is that true?
(I am using Visual Studio Community 2013 and Net Framework 4.5)
Your code works just fine. With a few extra touches it looks like this:

This is basically your code, applied to a normal DataGridView freshly dropped to the form..:
private void button1_Click_1(object sender, EventArgs e)
{
dataGridView1.DataSource = null;
dataGridView1.Rows.Clear();
dataGridView1.Columns.Clear();
sudokuTable = getTable();
dataGridView1.DataSource = sudokuTable;
for (int i = 0; i < 9; i++)
{
dataGridView1.Columns[i].Width = 25 + ((i+1)%3 == 0 ? 5:0);
}
dataGridView1.Columns[2].DividerWidth = 5;
dataGridView1.Columns[5].DividerWidth = 5;
dataGridView1.Rows[2].DividerHeight = 5;
dataGridView1.Rows[5].DividerHeight = 5;
dataGridView1.Rows[2].Height += 5;
dataGridView1.Rows[5].Height += 5;
dataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.RowHeadersVisible = false;
dataGridView1.ColumnHeadersVisible = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1[0, 0].Selected = false;
}
No changes at all to the getTable function..
Update: I was able to reproduce your problem. My DataGridView is on a TabPage which was not selected on startup. By calling the button click code before selecting the Tab I saw your error; when I put in a line to select the Tab first it worked again.. Looks like a problem/bug the DGV has with its layout when it isn't visible ..
Note: It never works when you call it in the constructor! That is too soon. Form_Load is fine, though..
As a temporary workaround, you can move the code to a Start Button. (Having a Start button is probably a good idea anyway, for the next round..)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With