Device selection in TreeView now fills in vendor and product ID in our text fields.
authorsl
Wed, 14 May 2014 17:26:04 +0200
changeset 58ea7a7e29c4d
parent 4 0220435cf48a
child 6 597a95926637
Device selection in TreeView now fills in vendor and product ID in our text fields.
FrmMain.cs
     1.1 --- a/FrmMain.cs	Wed May 14 16:37:44 2014 +0200
     1.2 +++ b/FrmMain.cs	Wed May 14 17:26:04 2014 +0200
     1.3 @@ -10,6 +10,7 @@
     1.4  using System.Windows.Forms;
     1.5  using System.Collections.Generic;
     1.6  using System.Drawing;
     1.7 +using System.Text.RegularExpressions;
     1.8  
     1.9  namespace GenericHid
    1.10  {
    1.11 @@ -597,6 +598,7 @@
    1.12              this.treeViewDevices.Name = "treeViewDevices";
    1.13              this.treeViewDevices.Size = new System.Drawing.Size(284, 461);
    1.14              this.treeViewDevices.TabIndex = 18;
    1.15 +            this.treeViewDevices.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewDevices_AfterSelect);
    1.16              //
    1.17              // FrmMain
    1.18              //
    1.19 @@ -2708,5 +2710,21 @@
    1.20  				return _transDefaultFormFrmMain;
    1.21  			}
    1.22  		}
    1.23 +
    1.24 +        private void treeViewDevices_AfterSelect(object sender, TreeViewEventArgs e)
    1.25 +        {
    1.26 +            //Node selected in our TreeView
    1.27 +            //Extract vendor and product IDs
    1.28 +            string deviceId = treeViewDevices.SelectedNode.Name;
    1.29 +            Regex regex = new Regex(@"VID_(....)&PID_(....).*");
    1.30 +            Match match = regex.Match(deviceId);
    1.31 +            if (match.Success)
    1.32 +            {
    1.33 +                //Take matches from each capturing group here. match.Groups[n].Value;
    1.34 +                //Put vendor and product ID in our text fields.
    1.35 +                txtVendorID.Text = match.Groups[1].Value;
    1.36 +                txtProductID.Text = match.Groups[2].Value;
    1.37 +            }
    1.38 +        }
    1.39  	}
    1.40  }