Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

update Window Form's list box.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
alan - 14 Oct 2004 06:55 GMT
I have 2 classes
form.cs and cls1.cs

in form.cs
using cls1_ns;
namespace form_ns
{
....public class formCls.....
public System.Windows.Forms.ListBox LstBox;
...}

in cls1.cs

using form_ns;
namespace cls1_ns
{
  class ...etc...
  static formCls cForm = new formCls();
  .....
  public void funcA()
  {
       ....
       cForm.LstBox.Add (....)
  }
}
}

this doesn't work, would you please tell how to update the value in window
form from another class?
thanks a lot!!!
Claes Bergefall - 14 Oct 2004 07:48 GMT
The code that you show should work just fine.
You'll need to provide more info/code

   /claes

> I have 2 classes
> form.cs and cls1.cs
[quoted text clipped - 26 lines]
> form from another class?
> thanks a lot!!!
alan - 14 Oct 2004 08:11 GMT
Label won't be updated, thanks!
here is my example :

Form1.cs

using Cls_ns;

namespace sampleFrm
{
public class Form1 : System.Windows.Forms.Form
{
    public System.Windows.Forms.Label label1;
    private System.Windows.Forms.Button button1;
    static Class1 cls = new Class1 ();
           ...etc....
    static void Main()
    {
        Application.Run(new Form1());
    }
    private void button1_Click(object sender, System.EventArgs e)
    {
        cls.update ();
    }
}
}

Class1.cs

------------------------------------------------------------------------------
using System;
using sampleFrm;

namespace Cls_ns
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class Class1
    {
        static Form1 frm = new Form1 ();
        public Class1()
        {
            //
            // TODO: Add constructor logic here
            //
           
        }

        public void update()
        {
            frm.label1.Text = "yeah";
        }
    }
}

> The code that you show should work just fine.
> You'll need to provide more info/code
[quoted text clipped - 31 lines]
> > form from another class?
> > thanks a lot!!!
Claes Bergefall - 14 Oct 2004 08:41 GMT
Well, you failed to mention that you already had an existing form.
Pass a reference of your exisiting form to the constructor of Class1

public class Form1 : System.Windows.Forms.Form
{
   private Class1 cls = new Class1(this);
}

public class Class1
{
   private Form1 m_frm;
   public Class1(Form1 frm)
   {
       m_frm = frm;
   }
   public void update()
   {
       m_frm.label1.Text = "yeah";
    }
}

   /claes

> Label won't be updated, thanks!
> here is my example :
[quoted text clipped - 86 lines]
> > > form from another class?
> > > thanks a lot!!!
alan - 14 Oct 2004 10:15 GMT
thanks!
but i get the following error

private Class1 cls= new Class1(this);

" Keyword this is not available in the current context"

> Well, you failed to mention that you already had an existing form.
> Pass a reference of your exisiting form to the constructor of Class1
[quoted text clipped - 111 lines]
> > > > form from another class?
> > > > thanks a lot!!!
alan - 14 Oct 2004 10:25 GMT
thanks a lot!
i have solved it

> Well, you failed to mention that you already had an existing form.
> Pass a reference of your exisiting form to the constructor of Class1
[quoted text clipped - 111 lines]
> > > > form from another class?
> > > > thanks a lot!!!
alan - 14 Oct 2004 08:17 GMT
is that when I instantiate -->
static formCls cForm = new formCls();

there will be a new "Form Class", so whatever I update, i just update on the
copy, but not the real form?
how can i solve the problem?

thanks!!!

> The code that you show should work just fine.
> You'll need to provide more info/code
[quoted text clipped - 31 lines]
> > form from another class?
> > thanks a lot!!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.