CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004

    Adding Text to a ListBox

    Using C# only, I have made a ListBox with TextBoxes (of Zone Descriptions). Works fine. How can I add Text in front of the TextBox that says Zone 1, Zone 2, etc'? I have created both TextBlocks and Strings, but can't get the Text to appear.

  2. #2
    Join Date
    Jul 2000
    Milano, Italy

    Re: Adding Text to a ListBox

    Quote Originally Posted by dodge55 View Post
    Using C#[...] TextBlocks and Strings, but can't get the Text to appear.
    This sounds like wpf
    In wpf, you must have a main container, inside which you can have other stuff and even nested containers.
    You should have your controls hosted in a container.
    You need to show us some of your code to get more help, but you can also find a sample of that stuff here
    Last edited by Cimperiali; March 23rd, 2012 at 03:35 PM.
    ...at present time, using mainly Net 4.0, Vs 2010

    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 2004

    Re: Adding Text to a ListBox

    It's not WPF. It's only C#. I use WPF for some controls, but I want to use on the fly C# for different arrangements of the screen space. My code is:

    ListBox LBZoneDesc = new ListBox();
    LBZoneDesc.Width = 300;
    LBZoneDesc.Height = 240;

    ListBoxItem[] LBI = new ListBoxItem[64];
    for (byte i = 0; i < 5; i++)
    TBlkZoneDesc[i].Margin = new Thickness((i*10), 10, 0, 0);
    LBI[i] = new ListBoxItem();
    LBI[i].Padding = new Thickness(3);
    LBI[i].Margin = new Thickness(50, 0, 0, 0);
    LBI[i].Content = TBxZoneDesc[i]; // TextBox of User entered Zone Desc.
    // LBZoneDesc.Items.Add(TBlkZoneDesc[i]); // TextBlock of 'Zone i'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.