Cannot enter dot in a textbox

2019-09-05 13:40发布

问题:

In my grid view i have link type column. as we cannot edit cell of such type i am displaying a text box if user select cell for editing. but my text box is unable read dot character. I checked "key pressed" and "text changed" events but events are not triggered for dot as a input.
EDIT: I can enter any character or symbol except dot.. ;(

I am displaying textbox on cell click event of gridview

if (DataGrid.Columns[e.ColumnIndex].GetType().Name == "DataGridViewLinkColumn")
{
txt_Data.Location    =   DataGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location;

txt_Data.Size        =   DataGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;

txt_Data.Visible     =   true;
txt_Data.Focus();
}

And assigning a value to cell as

private void txt_Data_TextChanged(object sender, EventArgs e)
{
  DataGrid.CurrentCell.Value = txt_Data.Text;
}

回答1:

I had this problem a few days ago and it was driving me nuts.. Finally figured it out so I've come back here to enlighten :) The problem is the EditingControlWantsInputKey method for your editing control.. Make sure it returns true for all characters (or at least the characters you want to support).. Done! :D