Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy/Paste functionality for DataGridView
Message
From
29/01/2007 13:53:53
 
 
To
27/01/2007 18:47:37
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01189883
Message ID:
01190231
Views:
14
Andrus,

The problem is because when using a DataGrid, the Form's ActiveControl is the DataGrid's DataGridTextBox, but when you use a DataGridView, the Form's ActiveControl is the DataGridView instead of it's TextBox. You'll need some additional code there to get around this (I don't have time to play with it right now, but hopefully you'll be able to figure it out ... play with it in the debugger).

You'll notice that the post that you got that from was a long time ago (back in 2002, might even have been 1.0 still ... I'm not sure when we started using 1.1) and DataGridView is new to 2.0. I haven't used a DataGridView yet (except to play with), so I don't have a quick answer for you at the moment.

~~Bonnie




>UT magazine contains Cut() etc. implementation solution provided by Bonnie Berent in Message #696109
>
>This is not working in case of DataGridView.
>
>How to implement cut/paste etc. edit menu also in case of DatagridView ?
>
>Here s repro of the issue
>
>Observed:
>
>first column is not empty
>
>Expected:
>
>first column must be empty
>
>Code to reproduce:
>
>
using System.Windows.Forms;
>using System.Data;
>static class Program {
>	static void Main() {
>		Application.Run(new Frm());
>	}
>}
>
>class Frm : Form {
>	public Frm() {
>		//this works: DataGrid dataGrid1 = new DataGrid();
>		DataGridView dataGrid1 = new DataGridView();
>		DataTable t = new DataTable();
>		t.Columns.Add();
>		t.Columns.Add();
>		t.Rows.Add("111111", "222222");
>		dataGrid1.DataSource = t;
>		dataGrid1.Dock = DockStyle.Fill;
>		Controls.Add(dataGrid1);
>	}
>
>	protected override void OnActivated(System.EventArgs e) {
>		base.OnActivated(e);
>		Control o = ActiveForm;
>
>		while (o is ContainerControl) {
>			ContainerControl oContainer = (ContainerControl)o;
>			o = oContainer.ActiveControl;
>		}
>		if (o != null && o is TextBox)
>			((TextBox)o).Cut();
>		SendKeys.SendWait("{TAB}");
>	}
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform