|
I have a form (form1.cs) that sends a transaction record variable (TranRec) to a program (Transporter.cs) by calling it using Transporter.ConnectToDMV(TranRec);.
Transporter.cs does what it needs to do and returns to form1.cs for the user to enter and submit another transaction. Here's part of the Transporter.cs code.
Transporter.cs
public partial class Transporter
{
public static void ConnectToDMV(string TranRec)
{ rest of code processing TranRec ...
What I also need Transporter.cs to do is return a variable (logLU) back to form1.cs. For this I am using the following code;
Transporter.cs
Form1 aForm = new Form1();
aForm.SetValue(logLU);
form1.cs
public void SetValue(string luValue)
{
logLU = luValue;
// for testing purposes
MessageBox.Show("Here's the value of (form1)luValue: " + luValue);
MessageBox.Show("Here's the value of (form1)logLU: " + logLU);
}
I can see both variables in the messageboxes so I know logLU gets to form1.cs but then it returns to null when I need it in other parts of form1.cs. What am I missing??? Similar code works in other parts of my program but not here. BTW, I'm a newbie to C# and this is my first application.
Any advise will be very much apprecaited. 
|
|
|
|
|
Form1 aForm = new Form1();
aForm.SetValue(logLU);
Looks like you are creating a new Form1 everytime you set this value.
The new form will have the value, but any existing form will not.
Try making aForm a field instead of a local variable and assigning the value to the field version of aForm.
|
|
|
|
|
Thank you for your reply. (Remember newbie)
I think I tried that but had syntax issues. What would the code you recommend look like?
Thanx again!
|
|
|
|
|
At the top of your code define the form.
private Form1 aForm ;
Where you are going to open the form:
aForm = new Form1 ( ) ;
Do some stuff here...
When you want to return the value to the form:
aForm.SetValue ( logLU ) ;
When you are done with the form, dispose of it.
|
|
|
|
|
I end up with the same result. Although I had to do the following because the use of private generated an invlaid expression term 'private' error.
namespace DMV_Test_1
{
public partial class Transporter
{
public static void ConnectToDMV(string TranRec)
{
Form1 aForm;
Thanx for the suggestion.
|
|
|
|
|
You need to put it here, outside of any method. Then it will be available anywhere in the class.
namespace DMV_Test_1
{
public partial class Transporter
{
Form1 aForm;
public static void ConnectToDMV(string TranRec)
{
|
|
|
|
|
When I did that I got the following error on the two instances of aForm
An object reference is required for the non-static field, method, or property
aForm = new Form1();
aForm.SetValue(logLU);
Thanx for the suggestion.
|
|
|
|
|
Hi,
Change your method to return the value directly
public static void ConnectToDMV(string TranRec)
public static string ConnectToDMV(string TranRec)
Alan.
|
|
|
|
|
Tried that but it caused other problems in the code.
I fixed the problem by doing the following in form1.cs
namespace DMV_Access_App
{
public partial class Form1 : Form
{
public static string logLU;
public Form1()
{ Rest of form1.cs code ...
This took care of the problem. Seems so simple. Of course, being a newbie, I am not sure what ramifications there are but it does work. This is great forum!

|
|
|
|
|
As an example I have two categories in a property grid. One is read-only and the other is editable.
I use a timer to automatically update the properties in the read-only category, approximately every 100msec. However for the updated values in the read-only category to be displayed properly I have to do a PropertyGrid.Refresh() call. This moves the focus inside the property grid, so if I'm editing an editable property I lose my focus anytime the timer fires.
Is there a simple way to work around this?
|
|
|
|
|
Have you tried using the respective ActiveControl and SetFocus methods?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Won't the ActiveControl always return the property grid? I'm losing focus within the property grid, not from the property grid.
|
|
|
|
|
Yeah, you're right.
I'm sort of guessing here; I misunderstood your original question. How about the SelectedGridItem property?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Yeah tried that. Didn't seem to do what I want.
|
|
|
|
|
I want to know if its possible to automate the System.Windows.Forms.WebBrowser and make it running in multiple threads.
I mean I want to login to say mysite.com , using 5 different accounts, Is it possible to do that simultaneously with 5 web browsers in 5 threads maintaining seperate sessions with the server of mysite.com,
Wont the sessions overlap with each other?
|
|
|
|
|
No, it's not. The WebBrowser will only work on the UI thread.
You don't need 5 seperate threads for this. Just 5 seperate WebBrowser controls.
indianbill007 wrote: Wont the sessions overlap with each other?
No.
|
|
|
|
|
Hi,
I am executing my windows application in Windows 7.
When i change the size of text to 125% or more, Window screen dosnt display properly.
|
|
|
|
|
I'd get a monitor that's 125% bigger.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
ohhh thanks for the reply
pavan
|
|
|
|
|
|
Please forgive me if this is a simple question -- I'm pretty new to C#.
Here's a quick code snippet that tries to take advantage of the ClearQuest API:
ClearQuestOleServer.SessionClass cqSession = new ClearQuestOleServer.SessionClass();
cqSession.UserLogon(login, password, dbName, (int)ClearQuestConstants.SessionType.AD_PRIVATE_SESSION, "");
object cqEntities = cqSession.GetEntityDefNames();
Now, when I run through this in the debugger and watch cqEntities, I can see that it's an array of strings (the "Type" field even claims that it's an "object {object[]}" type, with each item within it an "object {string}" type), but C# won't let me cast cqEntities as a string[], nor will it let me use cqEntities in a foreach (since it's not enumerable). What can I do to get at the stringy contents?
Thanks for any help you can offer!
|
|
|
|
|
I am not clear on your problems and I don't know the API:
object cqEntities = cqSession.GetEntityDefNames();
change to
String[] cqEntities = cqSession.GetEntityDefNames() as String[];
foreach (String str in cqEntities)
{
Console.Out.WriteLine(str);
}
Just let me know if it works
|
|
|
|
|
No, sadly, it doesn't; it merely sets up cqEntities as an array of nulls. Thanks, though!
|
|
|
|
|
Just a guess, but if you cast it (preferably with "as" and a null check) as an object[] first, you can then cast each element as a string in a foreach.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I'm having some luck with this one. Thanks! I should have thought of casting the function call as an array of objects myself!
modified on Thursday, December 17, 2009 10:29 AM
|
|
|
|