How do you cast a System::String __gc * to an int?

This is a discussion on How do you cast a System::String __gc * to an int? within the Windows Programming forums, part of the Platform Specific Boards category; Working in C++.NET... How do you cast a System::String __gc * to an int? I've got numbers 1-12 in a ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Question How do you cast a System::String __gc * to an int?

    Working in C++.NET...

    How do you cast a System::String __gc * to an int?

    I've got numbers 1-12 in a listbox. I want the user to be able to
    click on a number in the listbox and the event fired takes the
    number the user clicked and puts it into a case statement which
    runs a function with certain parameters, depending on which
    number it was. Any clue?

    Thanks for any suggestions.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You don't. As mentioned in your other thread on this topic you use the selected index.

    Code:
    int i = listboxRadStr->SelectedIndex;
    
    switch (i)
    {
        case -1:
            // No item selected
            break;
    
        case 0:
            // First item selected (1)
            break;
    
        case 1:
            // Second item selected (2)
            break;
    
         ...
    }
    As for adding multiple items, you could use a loop:
    Code:
    for (int i = 1;i <= 12;i++)
    {
        listboxRadStr->items->Add(i.ToString());
    }
    C++ with managed extensions has not been widely adopted and samples are hard to come by, even in the MS documentation. You may want to look into switching to C# for your CLR work.

    As I have not used MC++, I can't guarantee that the code I have posted will compile.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Talking Yes!!!!!!!!

    Thank you so much anonytmouse ! That simple little thing was hanging me up for so long and now it works! I appreciate it.

    Now, can you tell me how to empty the contents of a listbox programmatically?

    listboxRadStr->Clear?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Try:
    Code:
    listboxRadStr->Items->Clear();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 11:28 PM
  2. problem with sorting
    By pinkpenguin in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 11:06 AM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21