3 Replies - 388 Views - Last Post: 02 February 2012 - 10:15 PM Rate Topic: -----

Topic Sponsor:

#1 kingofleinster  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 09-December 08

Populating a Textbox\listbox ...bit confused

Posted 02 February 2012 - 04:13 PM

Hi Folks

Hoping you can help me, I pretty new to c# & a bit stuck\confused on how to populate a textbox.

The background of this is I'm trying to use the XenAPI with a gui to list the virtual machines on my host Xen server, I have the code from the xenserver website but the example it shows is for a console , Here is the sample code from the XENAPI sample.


List<XenRef<Host>> hostRefs = Host.get_all(sessions);

foreach (XenRef<Host> hostRef in hostRefs)

//obtain the full host record from the server

Host host = host.get_record)session, hostRef);

//display name & desc

System.Console.WriteLine("Name: {0}", host.name_label);
System.Console.WriteLine("Hostname: {0}", host.name_hostname);
System.Console.WriteLine("Description: {0}", host.name_description);
System.Console.WriteLine("-");

}





Basically I'm trying to get the textbox/listbox in the gui to print the same information that the console code above does , Just a bit confused of how to do it , I understand you will have use the listbox & the foreach statement , after that is where I get confused , What do I put in place instead of the System.Console ??

Any help greatly appreciated

Cheers
Paul

Is This A Good Question/Topic? 0
  • +

Replies To: Populating a Textbox\listbox ...bit confused

#2 tlhIn`toq  Icon User is offline

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3290
  • View blog
  • Posts: 6,896
  • Joined: 02-June 10

Re: Populating a Textbox\listbox ...bit confused

Posted 02 February 2012 - 05:17 PM

You set the .Text property of the textbox

myTextbox.Text = "Yogi Bear";


I will make a common suggestion though: Quit trying to develop your own application before you lean *how* to code in your chosen language. Trying to write a program from scratch as a learning exercise never works this early in your schooling.

This type of thing is covered very early on in any self-teaching book. Which makes me think you really aren't ready to be designing an application yet.

Some of the tutorials below are for C# not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.

Newbie/Rookie said:

I have a little programming experience but I need to write ...


You need to start there. I can't say "I have little experience in speaking Russian, but I have been assigned to write a mystery novel in Russian. Can you help me?"

We can help you by saying "First learn basic programming and the language of C#. Then take on assignments." Could someone here write this program for you? Sure. Could someone here map out all the processes you need to follow and do the Software Design part of this in the slim hope you could code it from there? Sure. But we don't volunteer to do the job that you're either getting paid for, or getting a grade for. You may want to read this.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3 act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).


Resources, references and suggestions for new programmers. - Updated Jan 2012
Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • No Sugar Coding Here!
  • member icon

Reputation: 4684
  • View blog
  • Posts: 20,362
  • Joined: 23-August 08

Re: Populating a Textbox\listbox ...bit confused

Posted 02 February 2012 - 08:51 PM

Perhaps this might help? It's the second link in a Google search of C# listbox.
Was This Post Helpful? 0
  • +
  • -

#4 cilaes  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 68
  • Joined: 12-December 11

Re: Populating a Textbox\listbox ...bit confused

Posted 02 February 2012 - 10:15 PM

Also, line 7, you have a parentheses aimed the wrong way...

Host host = host.get_record)session, hostRef);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1