private void addButton_Click(object sender, EventArgs e) { if (hostnameBox.Text.Trim().Length == 0 || updateUrlBox.Text.Trim().Length == 0 || usernameBox.Text.Trim().Length == 0 || passwordBox.Text.Trim().Length == 0) { MessageBox.Show(this, "Please fill all fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DynDnsHost host = null; foreach (var h in dynDnsListBox.Items) { if (((DynDnsHost)h).Hostname == hostnameBox.Text) { host = (DynDnsHost)h; } } if (host != null) { dynDnsListBox.Items.Remove(host); } host = new DynDnsHost() { Hostname = hostnameBox.Text, UpdateUrl = updateUrlBox.Text, Username = usernameBox.Text, Password = passwordBox.Text }; dynDnsListBox.Items.Add(host); }
private void dynDnsListBox_SelectedValueChanged(object sender, EventArgs e) { if (dynDnsListBox.SelectedItem == null) { return; } DynDnsHost host = (DynDnsHost)dynDnsListBox.SelectedItem; hostnameBox.Text = host.Hostname; updateUrlBox.Text = host.UpdateUrl; usernameBox.Text = host.Username; passwordBox.Text = host.Password; }