Any help ?? pls..?

Discussion in 'Programming & Scripting' started by Noobish, Jan 25, 2009 with 9 replies and 208 views.

  1. Noobish

    Noobish Newbie

    Messages:
    40
    Ratings:
    0
    is it possible to Convert text to a number ??,

    example:

    i have a combobox with a few items in it
    one , two , three , four , etc...

    and the combobox is linked to a URL

    (example)
    "[Click here to view the link]"+ combobox1.text + ".com"

    Is it possible to convert the text to a number , without to change the combobox text ? So the user still see the text ?
    but in the link will the text convert to a number
    (exampleNumber1.com ; exampleNumber2.com ; etc...)

    sorry if this was a noob Question , but i just started with C#


    Ps: Sorry for my english , i did my best :smile:. hope you can understand what i mean. :?
     
  2. dschu012

    dschu012 Member

    Messages:
    760
    Ratings:
    381
    When you add items to the combobox I would make it so the selectedValue of the item is what you want. For example add the item One and make its selected value 1. Then you would be able to do comboBox1.SelectedValue
    To do this to the comboBox I would do the following
    Code:
    Dictionary<string, int> data = new Dictionary<string, int>();
    data.Add("one", 1);
    comboBox1.DisplayMember = "Key";
    comboBox1.ValueMember = "Value";
    comboBox1.DataSource = new BindingSource(data, null);
    
    Then you add for comboBox1 for selectedIndex changed.
    Code:
    "[URL="http://www.examplenumber/"]www.exampleNumber[/URL]"+ combobox1.SelectedValue.ToString()+ ".com";
    
     
    • Like Like x 1
  3. OP
    Noobish

    Noobish Newbie

    Messages:
    40
    Ratings:
    0
    thanks , that works , but how do i add more data , displaymembers or Valuemembers in the combobox ?
    like in example : Two (2) , Three (3) , Four (4) , etc....
     
  4. dschu012

    dschu012 Member

    Messages:
    760
    Ratings:
    381
    The same way you added one.
    Code:
    data.Add("two",2);
    
     
  5. OP
    Noobish

    Noobish Newbie

    Messages:
    40
    Ratings:
    0
    ok , it worked for this :
    Code:
    [SIZE=2][COLOR=#2b91af]Dictionary[/COLOR][/SIZE][SIZE=2]<[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2]> data = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af]Dictionary[/COLOR][/SIZE][SIZE=2]<[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2]>();[/SIZE]
    [SIZE=2]data.Add([/SIZE][SIZE=2][COLOR=#a31515]"one"[/COLOR][/SIZE][SIZE=2], 1);[/SIZE]
    [SIZE=2]comboBox1.DisplayMember = [/SIZE][SIZE=2][COLOR=#a31515]"one"[/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]comboBox1.ValueMember = [/SIZE][SIZE=2][COLOR=#a31515]"1"[/COLOR][/SIZE][SIZE=2];[/SIZE]
    
    but When i try to add anything else it didn't work :?

    Code:
    [SIZE=2][COLOR=#2b91af]Dictionary[/COLOR][/SIZE][SIZE=2]<[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2]> data = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#2b91af]Dictionary[/COLOR][/SIZE][SIZE=2]<[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2]>();[/SIZE]
    [SIZE=2]data.Add([/SIZE][SIZE=2][COLOR=#a31515]"one"[/COLOR][/SIZE][SIZE=2], 1);[/SIZE][SIZE=2]
    comboBox1.DisplayMember = [/SIZE][SIZE=2][COLOR=#a31515]"one"[/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]comboBox1.ValueMember = [/SIZE][SIZE=2][COLOR=#a31515]"1"[/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]data.Add([SIZE=2][COLOR=#a31515]"two"[/COLOR][/SIZE][SIZE=2], 2);[/SIZE][/SIZE]
    [SIZE=2][SIZE=2]comboBox1.DisplayMember = [/SIZE][SIZE=2][COLOR=#a31515]"two"[/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]comboBox1.ValueMember = [/SIZE][SIZE=2][COLOR=#a31515]"2"[/COLOR][/SIZE][SIZE=2];[/SIZE]
    [/SIZE]
    i know i make a big mistake , but i'm just i little confused :?

    i want to add the values in the same Combobox...
     
  6. dschu012

    dschu012 Member

    Messages:
    760
    Ratings:
    381
    Do this
    Code:
    Dictionary<string, int> data = new Dictionary<string, int>();
    data.Add("one", 1);
    data.Add("two", 2);
    comboBox1.DisplayMember = "Key";
    comboBox1.ValueMember = "Value";
    comboBox1.DataSource = new BindingSource(data, null);
    
    Leave the Key and Value part do not put your own numbers.
     
    • Like Like x 1
  7. OP
    Noobish

    Noobish Newbie

    Messages:
    40
    Ratings:
    0
    yea it works now :wink:
    Thanks alot dschu012!! :biggrin:
     
  8. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    really, all of this over complicates the simple task he was wanting to do. But its good help.
     
  9. dschu012

    dschu012 Member

    Messages:
    760
    Ratings:
    381
    Always has been what I thought was the easiest way. Do you have another way to do it?
     
  10. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    i dont really understand whats hes trying to do, but i think this is right.

    after loading the items into a comboBox:

    Code:
    for (int i = 0; i < cBox.Length; i++)
    {
    [SIZE=2]     comboBox1.Items.RemoveAt(i);[/SIZE]
    cBox.Items.Insert(i, "[URL="http://www.examplenumber/"][COLOR=#36a200]www.exampleNumber[/COLOR][/URL]"+ (i + 1).ToString() + ".com");
    }