Example #1
0
        private void btnFindDevices_Click(object sender, EventArgs e)
        {
            frmWaitFindDevices dialog = new frmWaitFindDevices();

            dialog.Show(this);
            IList <DeviceNetworkAddress> devices = NetworkScanner.FindIpAddress(_macAddresses, _staticIpAddresses, Port).ToList();

            dialog.Close();
            dialog.Dispose();

            cmbIPAddresses.Items.Clear();
            if (devices.Any())
            {
                //cmbIPAddresses.DataSource = new BindingSource(devices.Select(d => new ComboboxItem { Text = d.IPAddress.ToString(), Value = d.IPAddress.ToString() }).ToList(), null);
                foreach (string address in devices.Select(d => d.IPAddress.ToString()))
                {
                    cmbIPAddresses.Items.Add(address);
                }

                if (devices.Count > 1)
                {
                    cmbIPAddresses.Text = "Select an IP address";
                    MessageBox.Show(
                        "Found more than 1 device on your local network. Please select one in the list and click the 'Connect' button.",
                        "Multiple devices found", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show(
                        "Found 1 device on your local network. Click the 'Connect button' to connect to it.",
                        "Device found", MessageBoxButtons.OK);
                }
            }
            else
            {
                cmbIPAddresses.Items.Add(new ComboboxItem {
                    Text = "Click 'Find'", Value = string.Empty
                });
                MessageBox.Show(
                    "Could not find any device. Be sure the Network Analyzer is powered on and connected to the network. When using DHCP it might take a while before the Network Analyzer has obtained an IP address.",
                    "No device found", MessageBoxButtons.OK);
            }
            cmbIPAddresses.SelectedIndex = 0;
        }