lundi 20 avril 2015

How can i read all the lines from a text file in specific places and use the data?

string[] lines = File.ReadAllLines(@"c:\wmiclasses\wmiclasses1.txt");
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("ComboBox"))
                {

                }
            }

And this is how the text file content look like:

ComboBox Name cmbxOption

Classes Win32_1394Controller
Classes Win32_1394ControllerDevice

ComboBox Name cmbxStorage

Classes Win32_LogicalFileSecuritySetting
Classes Win32_TapeDrive

What i need to do is some things:

  1. Each time the line start with ComboBox then to get only the ComboBox name from the line for example cmbxOption.

    Since i have already this ComboBoxes in my form1 designer i need to identify where the cmbxOption start and end and when the next ComboBox start cmbxStorage.

  2. To get all the lines of the current ComboBox for example this lines belong to cmbxOption:

Classes Win32_1394Controller Classes Win32_1394ControllerDevice

  1. To create from each line a Key and Value for example from the line:

Classes Win32_1394Controller

Then the key will be Win32_1394Controller and the value will be only 1394Controller

Then the second line key Win32_1394ControllerDevice and value only 1394ControllerDevice

  1. To add to the correct belonging ComboBox only the value 1394Controller.

  2. To make that when i select in the ComboBox for example in cmbxOption the item 1394Controller it will act like i selected Win32_1394Controller.

For example in this event:

private void cmbxOption_SelectedIndexChanged(object sender, EventArgs e)
        {
            InsertInfo(cmbxOption.SelectedItem.ToString(), ref lstDisplayHardware, chkHardware.Checked);

        }

In need that the SelectedItem will be Win32_1394Controller but the user will see in the cmbxOption only 1394Controller without the Win32_

This is the start of the method InsertInfo

private void InsertInfo(string Key, ref ListView lst, bool DontInsertNull)
        {

That's why i need that the Key will be Win32_1394Controller but i want that the user will see in the ComboBox only 1394Controller without the Win32_

Aucun commentaire:

Enregistrer un commentaire