我有一個checkedListBox和一個文本框......當我檢查了checkedListBox中的項目時,它顯示了TextBox中的相應項目的值.....當我檢查了多個項目checkedListBox它顯示文本框中由{,}「逗號分隔的各個項目的值有問題關於清單箱
現在我的問題是,當我取消選中文本框中的項目時,它必須從文本框中刪除相應未檢查項目的值......也PLZ告訴我如何以編程方式從文本框的末尾刪除「逗號」{,}
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");
}
}
ok先生,我會遵循這個編輯規則.....但現在你可以plz給我完美的答案... @ pravprab – user3304978