DataGridView单元格输入全角转半角

        //编辑单元格控件发生事件
private void GridDetail_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
//获取列序号
int columnIndex = GridDetail.CurrentCell.ColumnIndex;
//单元格转化成文本框
TextBox tb = e.Control as TextBox;
//委托单元格KeyPress事件
tb.KeyPress +=new KeyPressEventHandler(tb_KeyPress);
}

//单元格KeyPress事件
private void tb_KeyPress(object sender, KeyPressEventArgs e)
{
//全角转半角
if (e.KeyChar >= 65296 && e.KeyChar <= 65305)
{
e.KeyChar -= Convert.ToChar(65248);
}
}

 

你可能感兴趣的:(datagridview)