【发布时间】:2014-04-01 04:00:10
【问题描述】:
我有一个checkedListBox 和一个TextBox...当我检查checkedListBox 中的项目时,它会显示TextBox 中各个项目的值...当我检查checkedListBox 中的多个项目时,它会显示各个项目的值在以 {,}"逗号"
分隔的 TextBox 中现在我的问题是,当我取消选中文本框中的项目时,它必须从文本框中删除相应未选中项目的值......还请告诉我如何从末尾删除“逗号”{,}以编程方式显示文本框
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");
}
}
【问题讨论】:
-
好的先生,我会遵循这个编辑规则.....但是现在你能给我一个完美的答案......@ pravprab
标签: c# sql-server winforms