473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Set accessor not setting value

91
I have a statusbar and created a textbox to double test this however the value is being sent as I did a MessageBox.Show(value); and it shows the value being passed yet it is not being set. Can anyone explain why? Here is my code. The MainGUI is a partial class with : Form. Does that make a difference?

MainGUI Class
Expand|Select|Wrap|Line Numbers
  1. public string stsMessageText
  2. {
  3. get
  4. {
  5. return stsMessage.Text;
  6. }
  7. set
  8. {
  9. stsMessage.Text = value;
  10. MessageBox.Show("Value: " + value);
  11. }
  12. }
  13.  
database.cs
Expand|Select|Wrap|Line Numbers
  1. MainGUI main = new MainGUI();
  2. main.stsMessageText = "Connected to database";
  3.  
Any help would be appreciated.
May 22 '08 #1
11 1425
Plater
7,872 Expert 4TB
How fast are you doing this? sometimes you need to call .Update() on the object to make sure it gets re-drawn?
May 22 '08 #2
arggg
91
in Database.cs I now have
Expand|Select|Wrap|Line Numbers
  1. main.stsMessageText = "connected to database";
  2. main.Update();
  3.  
But this still does not make it display... any other ideas? Also thank you for the quick reply.
May 22 '08 #3
Plater
7,872 Expert 4TB
Hahaha I think I have it.
You are creating a NEW instance of your maingui class in that database call, not changing the one that is already shown.
May 22 '08 #4
arggg
91
Hahaha I think I have it.
You are creating a NEW instance of your maingui class in that database call, not changing the one that is already shown.
Yea i was just going to post that. How would I update the CURRENT instance? I am not familiar with a way of doing something in another class without first creating an instance...
May 22 '08 #5
Sick0Fant
121 100+
Yea i was just going to post that. How would I update the CURRENT instance? I am not familiar with a way of doing something in another class without first creating an instance...
Instead of setting the object equal to a new instance via the keyword "new", just declare the variable and set it equal to an already existing instance.
May 22 '08 #6
arggg
91
Instead of setting the object equal to a new instance via the keyword "new", just declare the variable and set it equal to an already existing instance.

Well I launched the application in the Main() with Application.Run(new MainGUI()); Well I didnt but VS2008 Express did. How should I proceed?

Sorry I'm new to c#
May 22 '08 #7
Sick0Fant
121 100+
Well I launched the application in the Main() with Application.Run(new MainGUI()); Well I didnt but VS2008 Express did. How should I proceed?

Sorry I'm new to c#
Is the form itself in which this code is contained an instance of MainGUI (if so, use this.stsMessageText)? I'm kind of confused.
May 22 '08 #8
arggg
91
Here is what I did with the help of a colleage.

MainGUI.cs
Expand|Select|Wrap|Line Numbers
  1. public string stsMessageText
  2. {
  3. set { stsMessage.Text = value; }
  4. }
  5.  
  6. Database db = new Database();
  7. db.dbConnect(this);
  8.  
database.cs
Expand|Select|Wrap|Line Numbers
  1. class Database
  2.  
  3. public void dbConnect(MainGUI main)
  4. {
  5. // ...
  6. main.stsMessageText = "Connected To Database";
  7. }
  8.  
I believe that is the direction you were pointing me in or atleast trying to tell me to day. Thanks for the advice!
May 22 '08 #9
Plater
7,872 Expert 4TB
That should work, maybe a bit exsesive, but should work.
May 22 '08 #10
arggg
91
what were you thinking?
May 22 '08 #11
Plater
7,872 Expert 4TB
Well you wanted to use that get/set thing, but I was thinking you were passing in a reference to the whole form when all you needed was that one control
May 23 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: mirandacascade | last post by:
When I look at how classes are set up in other languages (e.g. C++), I often observe the following patterns: 1) for each data member, the class will have an accessor member function (a...
22
by: Generic Usenet Account | last post by:
A lot has been said in this newsgroup regarding the "evil" set/get accessor methods. Arthur Riel, (of Vanguard Training), in his class, "Heuristis for O-O Analysis & Design", says that there is...
10
by: ma740988 | last post by:
I'm hoping my post here doesn't fall into the 'hard to say' category, nonetheless I've been advised that multiple uses of accessor/mutator (get/set) member functions can be viewed as a 'design...
10
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: šššššššštypedefšstructš{ ššššššššššššššššintššššši; ššššššššššššššššcharššššname; šššššššš}šMY_TYPE; ššššššššconstšcharš*
3
by: Mike Irwin | last post by:
I'm having a little difficulty with the set accessor. I'm working on a template-based site design and trying to use the set accessor to set the document's title. The problem is that it's not...
1
by: Pol Bawin | last post by:
Hi, I have a objectA with a property that return an object B (accessor GET only) I have defined an ExpandableObjectConverter on the type B and overrided CanConvertTo, CanConvertFrom, ... The...
6
by: Jason Shohet | last post by:
I have a class with protected variables and some accessor methods, , get, set ... Maybe I have a brain blockage today but I'm thinking, why not just make those variables public. After all,...
8
by: Steven Wolf | last post by:
Hi guys, maybe you can help me again in developing my bussiness project for a company.. i make sure, that each property of an entity, mark it self dirty when data get changed.. thats the...
3
by: Allerdyce.John | last post by:
I have a design type of quesiton. What is the advantages of using accessor (a getter/setter method) instead of making the attribute 'public'? If a class has public accessor (a getter/setter...
8
by: AAJ | last post by:
Hi all I would like to have a class that can set/return values of different datatype via a single accessor, i.e. overload the accessor i.e. something like DateTime m_DateValue; string...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.