Hey there,
I have a checkedListBox and a TextBox......Wh en I Checked item in the checkedListBox it shows the value of the respective item in the TextBox.....Whe n I Checked multiple items in the checkedListBox it shows the values of the respective items in the TextBox separating by {,}"Comma"
Now my question is that when I unchecked the item in the textBox it must remove the value of respective unchecked items from the textBox ......also plz tell me how do i remove "Comma"{,} from the end of the text box programmaticall y
I have a checkedListBox and a TextBox......Wh en I Checked item in the checkedListBox it shows the value of the respective item in the TextBox.....Whe n I Checked multiple items in the checkedListBox it shows the values of the respective items in the TextBox separating by {,}"Comma"
Now my question is that when I unchecked the item in the textBox it must remove the value of respective unchecked items from the textBox ......also plz tell me how do i remove "Comma"{,} from the end of the text box programmaticall y
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace listbox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True"); SqlCommand command = new SqlCommand("Select * FROM address_book ", connection); try { connection.Open(); { SqlDataReader drd = command.ExecuteReader(); while (drd.Read()) { this.checkedListBox1.Items.Add(drd.GetString(0).ToString()); } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } connection.Close(); } private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("select * from address_book where name='" + checkedListBox1.Text + "'", con); SqlDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { textBox1.Text += Convert.ToString(dr["id"] + ","); } dr.Close(); } private void textBox1_Enter(object sender, EventArgs e) { ToolTip tt = new ToolTip(); tt.SetToolTip(textBox1, "sorry"); } } }
Comment