troubleshooting Question

how to add a check box and a combo box to a list view?

Avatar of int_acct
int_acct asked on
C#
3 Comments1 Solution783 ViewsLast Modified:
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");
                        }
                  }
            }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros