C# question

C

Claudia Fong

Hi,

I'm quite new in C# programming and windows workflow foundation

I have a problem regarding a Local Communication Service question and is
like this:

I have an interface in my workflow:

[ExternalDataExchange]
public interface IHostCommunication
{
int Add(int x, int y);
}

public class Implementation : IHostCommunication
{

#region IHostCommunication Members

public int Add(int x, int y)
{
return (x + y);
}

#endregion
}


Then I set up all the properties in the CallExternalMethod Activity

In my code activity I have this code below:

private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Return Value was: {0}", ReturnValue); <-- INSTEAD OF
USING A CONSOLE APPLICATION, I'M USING WINFORM TO HOST THE WORKFLOW, SO
I WANT TO DISPLAY ReturnValue IN A LISTBOX THAT I HAVE IN MY FORM, CAN
SOMEONE TELL ME HOW?
}

private int x;
public int X
{
get { return x; }
set { x = value; }
}

private int y;
public int Y
{
get { return y; }
set { y = value; }
}

private int returnValue;
public int ReturnValue
{
get { return returnValue; }
set { returnValue = value; }
}

Cheers!

Claudi
 
P

Peter Duniho

[...]
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Return Value was: {0}", ReturnValue); <-- INSTEAD OF
USING A CONSOLE APPLICATION, I'M USING WINFORM TO HOST THE WORKFLOW, SO
I WANT TO DISPLAY ReturnValue IN A LISTBOX THAT I HAVE IN MY FORM, CAN
SOMEONE TELL ME HOW?
}

Why a ListBox? It seems to me that a TextBox or Label instance would be
more appropriate unless you have a sequence of return values that you
intend to add to the ListBox, and even then only if you expect the user to
be able to select one or more of the items in the ListBox so that you can
then later do something with them.

If you really want a ListBox, then you need to use the ListBox().Add()
method:

listBox1.Add(ReturnValue.ToString());

(I think technically you don't need the "ToString()" since you can add a
boxed int to a ListBox too. This is just as "for example")

If you're using a TextBox or Label, then instead you can do this:

textBox1.Text = ReturnValue.ToString();
or
label1.Text = ReturnValue.ToString();

Of course, note all of the above examples assume the default name for the
first instance of each given type added to your form. You'll have to use
your own variable names that make sense in your form.

Pete
 
S

spncc

private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Return Value was: {0}", ReturnValue); <-- INSTEAD OF
USING A CONSOLE APPLICATION, I'M USING WINFORM TO HOST THE WORKFLOW, SO
I WANT TO DISPLAY ReturnValue IN A LISTBOX THAT I HAVE IN MY FORM, CAN
SOMEONE TELL ME HOW?
}
i doubt if u use the winform to echo the message, maybe because u
cannot catch the return message coz the application already close
itself. a trick to pause the application before closing is to put

Console.Readline(); //<-- read nothing just press enter to close the
applicaiton in the result.

at the end of the application. u will now see the return message.

sometime the environment and how to code the console and winform
application is not the same. try not to switch it if not neccessary :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top