您的位置:首页 > 其它

DataGridView单元格输入全角转半角

2012-03-27 12:14 656 查看
//编辑单元格控件发生事件
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: