标签:winform datagridview 列大写 列只能输入数字
列大写:
说明:调用EditingControlShowing事件
private void dgvGoods_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) {
#region 条码列大写
if (dgvGoods.CurrentCell.ColumnIndex ==
4) {//列索引
DataGridView dgv = (DataGridView)sender;
if (e.Control is DataGridViewTextBoxEditingControl) {
DataGridViewTextBoxEditingControl editiongControl = (DataGridViewTextBoxEditingControl)e.Control;
if (dgv.CurrentCell.OwningColumn.Name == "列名") {
editiongControl.CharacterCasing = CharacterCasing.Upper;
} else {
editiongControl.CharacterCasing = CharacterCasing.Normal;
}
}
}
#endregion
}
列只能输入数字:
private void dgvGoods_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) {
// isDigit = false;
if (dgvGoods.CurrentCell.ColumnIndex == 9) {//列索引
// isDigit = true;
e.Control.KeyPress += new KeyPressEventHandler(TextBox_KeyPress);
}
}
//只能输入数字、删除、减号 减号=45
private void TextBox_KeyPress(object sender, KeyPressEventArgs e) {
if (isDigit == true) {
if (!char.IsDigit(e.KeyChar) && e.KeyChar!=45) {
if (e.KeyChar == 8) {
e.Handled = false;
} else {
e.Handled = true;
}
}
}
}
备注:列只能为数字,要注意一点(即注释部分 bool isDigit=falase;如果列索引不等于9,不会执行EditingControlShowing事件),如果不加上,其他列也只能输入数字了。
标签:winform datagridview 列大写 列只能输入数字
原文地址:http://blog.csdn.net/u013816709/article/details/41785623