int_acct
asked on
how to add a check box and a combo box to a list view?
My problem is like this , i has two columns Student Name ,Matric name in my listview and i want to add 2 columns to which is a check box (Absent) and combo box(State Of Absent) with value "yes" and "no" to the list view.
and i want when my list view display students name and matric from t01, (there are 20 students from t01). i want the check box and combo next to each of the row of student like example
Student Name Matric No Absent State of Absent
Lim siew yew 03030254E check box1 combo box 1
Lim wei wei 00000000Q check box2 combo box2
and so on and on......
currently my code can only do this
Student Name Matric No
Lim siew yew 03030254E
Lim wei wei 00000000Q
How can i do that,please guide me ,i am new to listview and c#
this is my code below for your reference.
private void comboBox1_SelectedIndexCha nged(objec t sender, System.EventArgs e)
{
if (comboBox1.SelectedIndex== 0)
{
try
{
SqlCeConnection connection = new SqlCeConnection(_localConn ectionStri ng);
connection.Open();
SqlCeCommand command = new SqlCeCommand("SELECT matric_no, student_name, tutorial_grp FROM tutorial1Class_listCE Where tutorial_grp= 't01';", connection);
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
DataTable tblData = new DataTable("Student");
adapter.Fill(tblData);
foreach (DataRow drowData in tblData.Rows)
{ listView1.Clear();
// add id first
ListViewItem item = new ListViewItem(drowData["mat ric_no"].T oString()) ;
// add sub item
item.SubItems.Add(drowData ["student_ name"].ToS tring());
// add item to list view
listView1.Items.Add(item);
}
}
catch (SqlCeException ce)
{
ShowErrors(ce);
}
catch (Exception er)
{
MessageBox.Show(er.ToStrin g());
}
finally
{
MessageBox.Show("ok", "RDA Lab");
}
}
}
and i want when my list view display students name and matric from t01, (there are 20 students from t01). i want the check box and combo next to each of the row of student like example
Student Name Matric No Absent State of Absent
Lim siew yew 03030254E check box1 combo box 1
Lim wei wei 00000000Q check box2 combo box2
and so on and on......
currently my code can only do this
Student Name Matric No
Lim siew yew 03030254E
Lim wei wei 00000000Q
How can i do that,please guide me ,i am new to listview and c#
this is my code below for your reference.
private void comboBox1_SelectedIndexCha
{
if (comboBox1.SelectedIndex==
{
try
{
SqlCeConnection connection = new SqlCeConnection(_localConn
connection.Open();
SqlCeCommand command = new SqlCeCommand("SELECT matric_no, student_name, tutorial_grp FROM tutorial1Class_listCE Where tutorial_grp= 't01';", connection);
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
DataTable tblData = new DataTable("Student");
adapter.Fill(tblData);
foreach (DataRow drowData in tblData.Rows)
{ listView1.Clear();
// add id first
ListViewItem item = new ListViewItem(drowData["mat
// add sub item
item.SubItems.Add(drowData
// add item to list view
listView1.Items.Add(item);
}
}
catch (SqlCeException ce)
{
ShowErrors(ce);
}
catch (Exception er)
{
MessageBox.Show(er.ToStrin
}
finally
{
MessageBox.Show("ok", "RDA Lab");
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
er thk but the code seen a bit 2 less and hard.can u write some simple code for me on how to insert check box based on my code above......
ASKER