Muralidhar GVN

Good Morning.

We have a legacy Windows Forms application designed in .NET 1.1.

The UI has a Group Box control with 5 text boxes and a button; and a DataGrid control below the Group Box.

When ever user enteres some data in the text boxes and clicks on the button, this information will be populated in DataGrid component. Only row selection is enabled in the DataGrid. If the user selects a row, the data in the row will be populated in the appropriate text boxes in the Group Box and the focus should be placed in the text box.

Question:

-------------

We need to implement the vertical scroll for DataGrid component using Mouse Wheel.

We found that unless otherwise the DataGrid contains focus on it, the vertical scroll is not getting implemented using the mouse wheel; but, as per client's requirement, when the user selects a row, immediately the focus should be placed in first text box in the group box. Thats why we were unable to implement the vertical scroll using mouse wheel.

Can anyone help in this regard

Thanks in advance,

Muralidhar.



Re: Windows Forms Designer Implementation of Scroll in DataGrid using Mouse Roller Ball

Karthikeya Pavan Kumar .B

check this link




Re: Windows Forms Designer Implementation of Scroll in DataGrid using Mouse Roller Ball

Yu Guo – MSFT

Hi, Muralidhar,

I tried to establish this by setting the MouseWheel event on the TextBox,

but first, we will have to create a Custom DataGrid

Code Snippet

class ScrollDataGrid : DataGrid

{

public ScrollDataGrid()

{

}

/// <summary>

/// scroll the grid to a particular row

/// </summary>

/// <param name="rowNumber"></param>

public void ScrollTo(int rowNumber)

{

if (this.DataSource != null)

{

GridVScrolled(this, new ScrollEventArgs(ScrollEventType.LargeIncrement, rowNumber));

}

}

public void ScrollUp()

{

if (this.DataSource != null)

{

GridVScrolled(this, new ScrollEventArgs(ScrollEventType.SmallDecrement, this.CurrentRowIndex - 1));

}

}

public void ScrollDown()

{

if (this.DataSource != null)

{

GridVScrolled(this, new ScrollEventArgs(ScrollEventType.SmallIncrement, this.CurrentRowIndex + 1));

}

}

}

And then you can just use this DataGrid to scroll programmatically,

For example,

Code Snippet

public Form4()

{

InitializeComponent();

textBox1.MouseWheel += new MouseEventHandler(textBox1_MouseWheel);

}

void textBox1_MouseWheel(object sender, MouseEventArgs e)

{

if (e.Delta > 0)

grid.ScrollUp();

else if (e.Delta < 0)

grid.ScrollDown();

}

ScrollDataGrid grid;

private void Form4_Load(object sender, EventArgs e)

{

DataTable dt = new DataTable();

dt.Columns.Add("col1");

dt.Columns.Add("col2");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("abc", "bcd");

dt.Rows.Add("efg", "hij");

grid = new ScrollDataGrid();

grid.DataSource = dt;

grid.Width = 400;

grid.Height = 120;

this.Controls.Add(grid);

}

Hopes this helps,

Regards