Question

I am new in C#, I searched everywhere and didn't find any solution.

private void kryptonButton5_Click(object sender, EventArgs e)
    {
        adapters();
        MessageBox.Show(listBox1.Text);//How to get selected card name only ?
    }

    private void adapters()
    {
        foreach (NetworkInterface net_card in NetworkInterface.GetAllNetworkInterfaces())
        {
           listBox1.Items.Add(net_card.Name + "  " + net_card.Description + "  " + net_card.Id);
        }
    }

How can i get only the selected card name?

Was it helpful?

Solution

You can try this :

    var selectedValues = listBox1.SelectedItem.ToString().Split('  ');

    if (selectedValues.Length == 3)
    {
       var cardName = selectedValues[0];
       MessageBox.Show(cardName);
    }

Hope this help.

OTHER TIPS

Whenever you come across an object in the .NET framework that you are unfamilier with, take a few minutes to read the documentation. You can do this quickly by placing the caret on the type name and pressing F1.

Read the type description and then read the names and brief descriptions of every member of that type. Most objects in the framework document also give example code for how to use them.

Here is the ListBox Class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top