Link to home
Start Free TrialLog in
Avatar of int_acct
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_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  if (comboBox1.SelectedIndex==0)
                  {
                        
                        try
                        {
                              SqlCeConnection connection = new SqlCeConnection(_localConnectionString);
                              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["matric_no"].ToString());
                                    // add sub item
                                    item.SubItems.Add(drowData["student_name"].ToString());
                                          
                                    // add item to list view
                                          
                                    listView1.Items.Add(item);
                              }
                   
                         }
                        catch (SqlCeException ce)
                        {
                              ShowErrors(ce);
                        }
                        catch (Exception er)
                        {
                              MessageBox.Show(er.ToString());
                        }
                        finally
                        {
                              MessageBox.Show("ok", "RDA Lab");
                        }
                  }
            }
Avatar of int_acct
int_acct

ASKER

everyone .pleas help me
ASKER CERTIFIED SOLUTION
Avatar of sohamraj
sohamraj

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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......