Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value from combobox using substring in C#

Tags:

c#

combobox

I have a combo box which have item strings like:

1 .  Apple
2 .  Banana
3 .  Mango 

1,2,3 are category id & Apple, Banana, Mango is Category Name.

I want to know Category Id From comboBox using Category name which is sub-string of ComboBox item.

example:

I want to know the Category Id of Banana. which is 2.

Any help ?

like image 754
syed Ahsan Jaffri Avatar asked Dec 19 '25 17:12

syed Ahsan Jaffri


1 Answers

Use this code to an event that should be after you selected the item in comboBox :

        string []str;
        str = comboBox1.Text.Split(' ');
        string categoryId = str[0];
like image 79
Hamed Avatar answered Dec 21 '25 08:12

Hamed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!