tommie Posted August 17, 2004 Share Posted August 17, 2004 M = Main form X = Input form Using X, how can I work with M? :hmmm: Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted August 17, 2004 Share Posted August 17, 2004 Well, you can get M into a variable somehow in X, either through the constructor or through another method. Then beyond that, I would interact through methods in M. Not knowing how you want to interact makes it tough for me to recommend stuff though. If you just want information to go back and forth, then that's the easiest way. You could even have M handle events for X if you wanted. Link to comment Share on other sites More sharing options...
0 tommie Posted August 17, 2004 Author Share Posted August 17, 2004 Headache over here, I could just use an example on how to copy ListView items from X to M, by clicking a button on X. Not a whole example, just how to access M's ListView from X. Link to comment Share on other sites More sharing options...
0 MrRogers Posted August 17, 2004 Share Posted August 17, 2004 (edited) Form X { ? private ListView MyListView; ? //Some Method that you call to show Y or whatever? ? void SomeMethod() ? { ? ? Y myY = new Y(); ? ? myY.SetListView(MyListView); ? ? myY.Show(); ? } } Form Y { ? private ListView SomeListView; ? public void SetListView(ListView lv) ? { ? ? ? SomeListView = lv; ? } } quick code, but maybe that's what you need. Edited August 17, 2004 by MrRogers Link to comment Share on other sites More sharing options...
0 tommie Posted August 17, 2004 Author Share Posted August 17, 2004 (edited) Just did this to kind of show what I'm trying to do: (Doesn't work though) Form M { private System.Windows.Forms.ListView myListView; private void ShowX() { X showX = new X; showX.Show(); } public void AddItem(string sText) { myListView.Items.Add(sText); } } Form X { private System.Windows.Forms.TextBox myTextBox; private void ButtonClick(BlahBlah) { M myM; // I want the default instance, not a new instance, but this doesn't work. myM.AddItem(myTextBox.Text); } } Edited August 17, 2004 by tommie Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 17, 2004 Share Posted August 17, 2004 Do what kjordan said. Create an overloaded constructor that takes an M as an argument. class X : Form { private M _myM; public X(M m) { _myM = m; } } Link to comment Share on other sites More sharing options...
0 tommie Posted August 17, 2004 Author Share Posted August 17, 2004 Thanks guys. :D Link to comment Share on other sites More sharing options...
Question
tommie
M = Main form
X = Input form
Using X, how can I work with M? :hmmm:
Link to comment
Share on other sites
6 answers to this question
Recommended Posts