|
Hello,
At design time in VS2003 I can access the rows of a DataTable which has been connected to via a DataAdapter. I've got a very simple UserControl as an example to show you how I do it:
[Designer(typeof(UserControl1.UserControl1Designer))] public class UserControl1 : System.Windows.Forms.UserControl { //standard UserControl class with no changes //nested Designer class internal class UserControl1Designer : System.Windows.Forms.Design.ControlDesigner { public UserControl1Designer() : base() { AddVerbs(); }
private void AddVerbs() { Verbs.Add(new DesignerVerb("Test",new EventHandler(OnTest))); }
private void OnTest(object sender, EventArgs e) { System.Windows.Forms.Form f = base.Control.FindForm(); IContainer co = f.Container;
MessageBox.Show("OnTest");
if (co!=null) { foreach (object o in co.Components) { if (o is DataAdapter) { DataAdapter d=o as DataAdapter; DataSet dataset=new DataSet(); d.Fill(dataset); DataTable table = dataset.Tables[0]; MessageBox.Show(table.Rows.Count.ToString()); } } } } } }
However, at design time in VS2005 the automatically generated TableAdapter base class is a Component with no Fill method, meaning that I can't access the underlying DataTable's rows. It really would be most useful if the automatically generated TableAdapters implemented the IDataAdapter interface to allow something similar to the above to work. In the absence of such an implemention, does anybody know how I can access DataTable rows at design time in VS2005 using my UserControl?
Many thanks!
|