• 0

[C#] default instance functionality


Question

6 answers to this question

Recommended Posts

  • 0

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

  • 0

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

  • 0

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 by MrRogers
Link to comment
Share on other sites

  • 0

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 by tommie
Link to comment
Share on other sites

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.