Does "DataGridView.HitTestInfo" have a "DataGrid.HitTestType.RowResize"?

Hi,

If I wish to obtain functionality similar to "HitTestType.RowSize", what would be the best way to go about it in regards with DataGridView?

The enum-structureDataGridViewHitTestType doesn't appear to have RowResize.

The following example is with DataGrid, but how would you code it with DataGridView?


classPhilGrid : System.Windows.Forms.DataGrid

{

overrideprotectedvoid OnMouseDown(MouseEventArgs e)

{

base.OnMouseDown(e);

DataGrid.HitTestInfo hti =this.HitTest(e.X, e.Y);

if (hti.Type ==DataGrid.HitTestType.RowResize)

{//Do stuff}
}
}

Philip

[2059 byte] By [PhilipL.N.] at [2007-12-16]
# 1

Hello Philip,
I just wrote a little app with the DataGridView and hooked up its CellMouseDown event. This event handler tells you if the mouse is within the hot zone for row resizing:

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == -1 && e.RowIndex > -1)
{
// User clicks a row header
int resizedRowIndex = -1;
int mouseY = e.Y;
if (mouseY < DATAGRIDVIEW_rowSizingHotZone)
{
// Possibly resizing the row above e.RowIndex
resizedRowIndex = this.dataGridView1.Rows.GetPreviousRow(e.RowIndex, DataGridViewElementStates.Visible | DataGridViewElementStates.Displayed);
}
else
{
int rowHeight = this.dataGridView1.Rows.SharedRow(e.RowIndex).Height;
if (rowHeight - mouseY < DATAGRIDVIEW_rowSizingHotZone)
{
// Resizing the row e.RowIndex
resizedRowIndex = e.RowIndex;
}
}
if (resizedRowIndex == -1)
{
// "Not resizing row"
}
else
{
// "Resizing row " + resizedRowIndex.ToString()
}
}
}

Note that I defined:
private const byte DATAGRIDVIEW_rowSizingHotZone = 5;

Hope this helps,
-regis
DataGridView Developer
Microsoft
This post is provided "as-is"

RegisBrid at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

Hi Regis,

Excellent example. I had a feeling that it would be possible to do it meassuring on the y-value compared to the size of the row-header.
Thank you very much

Philip

PhilipL.N. at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...