M
michael sorens
I want to be able to increase or decrease row heights of a populated
DataGridView from the keyboard. I set up a test program with menu items to
increase and decrease, assigned shortkey keys (ctrl-UpArrow and
ctrl-DnArrow), and attached handlers that execute this code:
public partial class MainForm : Form
{
. . .
dataGridView.RowTemplate.Height += increment;
Refresh();
. . .
}
I was surprised that this works reliably to change existing row heights
because a web search seemed to indicate that would only work for rows created
after that setting was done.
My real goal, though, is to internalize this functionality into my own
CustomDataGridView that derives from DataGridView. I worked out the
appropriate key activations so that the DataGridView would correctly listen
and respond to ctrl-UpArrow and ctrl-DnArrow. So I am certain it is executing
the same code effectively:
partial class CustomDataGridView : DataGridView
{
. . .
if (e.Control && e.KeyCode == Keys.Up)
{
Console.WriteLine("got ctrl-Up");
RowTemplate.Height += 1;
Refresh();
}
. . .
}
But in this test program, the rows do not change height. (I even tried
Parent.Refresh(); to make the code identical to the previous test but it
still fails.)
So:
(1) Should the first test scenario work?
(2) Why does the second test scenario fail?
(3) How do I get the second scenario to work?
Thanks!
DataGridView from the keyboard. I set up a test program with menu items to
increase and decrease, assigned shortkey keys (ctrl-UpArrow and
ctrl-DnArrow), and attached handlers that execute this code:
public partial class MainForm : Form
{
. . .
dataGridView.RowTemplate.Height += increment;
Refresh();
. . .
}
I was surprised that this works reliably to change existing row heights
because a web search seemed to indicate that would only work for rows created
after that setting was done.
My real goal, though, is to internalize this functionality into my own
CustomDataGridView that derives from DataGridView. I worked out the
appropriate key activations so that the DataGridView would correctly listen
and respond to ctrl-UpArrow and ctrl-DnArrow. So I am certain it is executing
the same code effectively:
partial class CustomDataGridView : DataGridView
{
. . .
if (e.Control && e.KeyCode == Keys.Up)
{
Console.WriteLine("got ctrl-Up");
RowTemplate.Height += 1;
Refresh();
}
. . .
}
But in this test program, the rows do not change height. (I even tried
Parent.Refresh(); to make the code identical to the previous test but it
still fails.)
So:
(1) Should the first test scenario work?
(2) Why does the second test scenario fail?
(3) How do I get the second scenario to work?
Thanks!