Reputation: 382
I wonder there are no posts on internet for this question, How do I add scrollbar to work on DataGridViewTextBoxColumn after MyGrid_EditingControlShowing event displays this textbox on grid.
I have added below event
private void MyGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if ((!(e.Control is TextBox)) || e.CellStyle.WrapMode == DataGridViewTriState.True) return;
var textBox = e.Control as TextBox;
textBox.ScrollBars = ScrollBars.Both;
}
but it didn't worked, when mouse scrolled it scrolled to grid's row not on cell
thanks in advance
Upvotes: 0
Views: 424
Reputation: 54433
This:
!(e.Control is TextBox))
will never be true.
You can try this instead:
if (MyGrid.CurrentCell.EditType != typeof(DataGridViewTextBoxEditingControl))
{
return;
}
Or this:
DataGridViewTextBoxEditingControl tb = e.Control as DataGridViewTextBoxEditingControl;
if (tb == null)
{
return;
}
Note that the ScrollBars
will still only show when the Cell
is in edit mode! The 'Cells' of a DateGridView
are only virtual controls or, in other words, they are just pixels painted on the screen. They have no event model etc, so they can't function interactively. Only the EditControl
that gets overlaid is an actual control.
Upvotes: 0