Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ADO.NET WinForm
I have a DataGridView with Readonly textbox column, i want to restrict from pasting into column.
 

thx in advance
Posted 5-Jul-13 7:32am
Comments
CHill60 at 5-Jul-13 13:38pm
   
Surely if you've made the column read-only then no-one can paste anything into it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v3
Comments
Ravi Sargam at 5-Jul-13 14:22pm
   
It is editable textbox column
Ravi Sargam at 5-Jul-13 14:36pm
   
i am using it on windows form
jaideepsinh at 5-Jul-13 14:46pm
   
Check my solution i have updated.
Ravi Sargam at 5-Jul-13 15:07pm
   
Thx a lot jai, its working...
jaideepsinh at 8-Jul-13 1:03am
   
Please dear accept as answer if solve your problem.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 190
1 PIEBALDconsult 150
2 BillWoodruff 148
3 DamithSL 140
4 Jochen Arndt 125
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 5 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100