我正在用MySQL(C#)以win形式進行大學學生考勤項目。如何在C#中獲得兩列winform列表框?
因爲我想將數據一個列表框移動到另一個列表框。我做到了。但我加載學生的名字。現在,客戶想要的名稱和adminno就像datagridview Columns一樣。
我搜索這個,。 Vb有這種類型的編碼。請參閱Multi Column Listbox。在C#中可能嗎?
請參閱下圖。它的我的形式。..
我的代碼加載列表框
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select name,admin_no from student_admision_master where course='" + course_code + "' AND year='" + year_code + "' AND sem='" + semester_code + "' AND batch='" + batch_code + "'";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
listBox1.Items.Add(Reader[0].ToString() + "," + Reader[1].ToString());
}
connection.Close();
這給結果jagadees,125445. 但想不同的單獨的列。
我的代碼移動數據的
private void btn_toAb_Click_Click(object sender, EventArgs e)
{
int count = listBox1.Items.Count;
for (int i = 0; i < count; i++)
{
listBox2.Items.Add(listBox1.Items[i].ToString());
}
listBox1.Items.Clear();
}
private void btn_fromAb_Click_Click(object sender, EventArgs e)
{
int count = listBox2.Items.Count;
for (int i = 0; i < count; i++)
{
listBox1.Items.Add(listBox2.Items[i].ToString());
}
listBox2.Items.Clear();
}
private void btn_toAb_Selected_Click(object sender, EventArgs e)
{
int count = listBox1.SelectedItems.Count;
for (int i = 0; i < count; i++)
{
listBox2.Items.Add(listBox1.SelectedItems[i].ToString());
}
for (int i = 0; i < count; i++)
{
listBox1.Items.Remove(listBox1.SelectedItems[0]);
//listBox1.add
}
}
private void btn_fromAb_Selected_Click(object sender, EventArgs e)
{
int count = listBox2.SelectedItems.Count;
for (int i = 0; i < count; i++)
{
listBox1.Items.Add(listBox2.SelectedItems[i].ToString());
}
for (int i = 0; i < count; i++)
{
listBox2.Items.Remove(listBox2.SelectedItems[0]);
}
}
提前感謝!...
感謝信息,, – Sagotharan