Click here to Skip to main content
14,882,317 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataGridView with Readonly textbox column, i want to restrict from pasting into column.


thx in advance
Posted
Comments
CHill60 5-Jul-13 13:38pm
   
Surely if you've made the column read-only then no-one can paste anything into it?

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

C#
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.
   
v3
Comments
Ravi Sargam 5-Jul-13 14:22pm
   
It is editable textbox column
Ravi Sargam 5-Jul-13 14:36pm
   
i am using it on windows form
jaideepsinh 5-Jul-13 14:46pm
   
Check my solution i have updated.
Ravi Sargam 5-Jul-13 15:07pm
   
Thx a lot jai, its working...
jaideepsinh 8-Jul-13 1:03am
   
Please dear accept as answer if solve your problem.
Try:

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900