Datagridveiw里如何实现只能输入固定位数数字并且可以Ctrl c Ctrl v? 本帖最后由 bwcigs 于 2009-07-28 17:01:52 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 赋值到剪切板Clipboard.SetDataObject(this.dataGridView1.GetClipboardContent()); 我是需要是ctrl c ctrl v按键操作不被e.e.HandledClipboard.SetDataObject(this.dataGridView1.GetClipboardContent());请问这句怎么用? DataGridView.ClipboardCopyMode 属性被设定为 DataGridViewClipboardCopyMode.Disable 以外的情况时,「Ctrl + C」 按下的时候,被选择的单元格的内容会拷贝到系统剪切板内。Clipboard.SetDataObject(DataGridView1.GetClipboardContent()) if (DataGridView1.CurrentCell == null) return;int insertRowIndex = DataGridView1.CurrentCell.RowIndex;string pasteText = Clipboard.GetText();if (string.IsNullOrEmpty(pasteText)) return;pasteText = pasteText.Replace(" ", " ");pasteText = pasteText.Replace(' ', ' ');pasteText.TrimEnd(new char[] { ' ' });string[] lines = pasteText.Split(' ');bool isHeader = true;foreach (string line in lines){ if (isHeader) { isHeader = false; continue; } string[] vals = line.Split(' '); if (vals.Length - 1 != DataGridView1.ColumnCount) throw new ApplicationException("粘贴的列数不正确。"); DataGridViewRow row = DataGridView1.Rows[insertRowIndex]; row.HeaderCell.Value = vals[0]; for (int i = 0; i < row.Cells.Count; i++) { row.Cells[i].Value = vals[i + 1]; } insertRowIndex++;} 但是现在的问题是我在keypress事件里已经做了如下处理private void dataGridViewTextBox_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b') { e.Handled = true; } }ctrl c ctrl v按下后就e.Handled = true; 同意楼上的,你在keypress里面判断一下ctrl+c是否被按下不就行了嘛 ctrl c ctrl v的keychar是? 查了一下是3和22但是问题又来了前面在keypress里禁止了非数字字符输入,通过复制却可以。 C#中如何发送HTTP请求,菜鸟求帮助 C# 多文档窗口问题 急用 winform 一个数据解密的问题 谁知道漂亮的C#菜单 wcf 错误400 bad request 这是不是C#的BUG? 高手解决 SYSTEM用户访问共享资源的问题 c#开发linphone c#对Excel添加行 用C#实现UDP通信的问题
Clipboard.SetDataObject(this.dataGridView1.GetClipboardContent());
请问这句怎么用?
return;
int insertRowIndex = DataGridView1.CurrentCell.RowIndex;
string pasteText = Clipboard.GetText();
if (string.IsNullOrEmpty(pasteText))
return;
pasteText = pasteText.Replace(" ", " ");
pasteText = pasteText.Replace(' ', ' ');
pasteText.TrimEnd(new char[] { ' ' });
string[] lines = pasteText.Split(' ');
bool isHeader = true;
foreach (string line in lines)
{
if (isHeader)
{
isHeader = false;
continue;
}
string[] vals = line.Split(' ');
if (vals.Length - 1 != DataGridView1.ColumnCount)
throw new ApplicationException("粘贴的列数不正确。");
DataGridViewRow row = DataGridView1.Rows[insertRowIndex];
row.HeaderCell.Value = vals[0];
for (int i = 0; i < row.Cells.Count; i++)
{
row.Cells[i].Value = vals[i + 1];
}
insertRowIndex++;
}
private void dataGridViewTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
{
e.Handled = true;
}
}ctrl c ctrl v按下后就e.Handled = true;
但是问题又来了
前面在keypress里禁止了非数字字符输入,通过复制却可以。