user1562839
user1562839

Reputation: 97

How to get nic card value from list in C#?

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?

Upvotes: 0

Views: 238

Answers (2)

Saber Amani
Saber Amani

Reputation: 6489

You can try this :

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

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

Hope this help.

Upvotes: 1

Tergiver
Tergiver

Reputation: 14517

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.

Upvotes: 0

Related Questions