Click here to Skip to main content
12,078,742 members (48,828 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ADO.NET
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 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 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.
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 5 Jul 2013
Copyright © CodeProject, 1999-2016
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