如何禁用粘贴选项DataGridview TextBoxColumn [英] How to Disable Paste option DataGridview TextBoxColumn

查看:109
本文介绍了如何禁用粘贴选项DataGridview TextBoxColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Readonly文本框列的DataGridView,我想限制粘贴到列中。





thx提前

I have a DataGridView with Readonly textbox column, i want to restrict from pasting into column.


thx in advance

推荐答案

在网格视图行数据绑定列上设置文本框只读属性,这样用户无法进入文本框。

如果不解决你的问题在这里粘贴代码。



在行数据绑定上使用此代码:



private void textBox1_KeyDown (对象发送者,KeyEventArgs e)

{

if(e.Modifiers == Keys.Control)

{

e.Handled = true;

textBox1.SelectionLength = 0;

}

}







Set text box read only property on grid view row data bound column this way user can't enter into text box.
If not solve your problem paste you code here.

Use this code on row data bound:

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.Control)
{
e.Handled = true;
textBox1.SelectionLength = 0;
}
}

Or

private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control == true)
            {
                MessageBox.Show("Cut/Copy and Paste Options are disabled");
            }
        }







如果解决问题,接受回答并投票。




Accept as answer and vote if solve your problem.


尝试:



< asp:textbox id =yourControlIdrunat =serveroncopy =return false onpaste =return falseoncut =return falseondelete =return falsexmlns:asp =#unknown>
Try:

<asp:textbox id="yourControlId" runat="server" oncopy="return false" onpaste="return false" oncut="return false" ondelete="return false" xmlns:asp="#unknown">


这篇关于如何禁用粘贴选项DataGridview TextBoxColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆