Adding Text to a ListBox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Adding Text to a ListBox

  1. #1
    Join Date
    Mar 2004
    Posts
    25

    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
    Location
    Milano, Italy
    Posts
    7,726

    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
    http://stackoverflow.com/questions/9...x-with-textbox
    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
    Posts
    25

    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;
    Grid.SetColumn(LBZoneDesc,0);
    Grid.SetRow(LBZoneDesc,2);

    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'
    LBZoneDesc.Items.Add(LBI[i]);
    }
    C0Grid.Children.Add(LBZoneDesc);

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

This is a CodeGuru survey question.


Featured


HTML5 Development Center