Vuk Stanojevic

Vuk Stanojevic

  • 1.6k
  • 140
  • 45.6k

C# Listview one columns with two rows

Apr 12 2020 9:30 AM
Hi everyone,
Im trying to create listview with two headers.
Main header is regular one.
But line bellow should be another header but with two cells.
In "2nd" header there should be only text.
And in all other rows there should be checkboxes.
 
Here is the picture how it should look like. 
What i have in this moment is:
  1. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3. listView1.Columns.Clear();  
  4. SqlConnection con = new SqlConnection(@"Data Source=MAIN-PC\SQLEXPRESS;Integrated Security=True");  
  5. SqlCommand cmd = new SqlCommand("USE "+comboBox1.Text+" ; Select * FROM stores",con);  
  6. DataTable dt = new DataTable();  
  7. con.Open();  
  8. SqlDataAdapter da = new SqlDataAdapter(cmd);  
  9. da.Fill(dt);  
  10. ListView view = new ListView();  
  11. view.View = View.Details;  
  12. //Header 1 - first column is text, other column names are equal to database values  
  13. listView1.Columns.Add("Store", 120, HorizontalAlignment.Left);  
  14. foreach(DataRow row in dt.Rows)  
  15. {  
  16. listView1.Columns.Add(row[0].ToString()+" """+row[1].ToString()+"" , 80, HorizontalAlignment.Left);  
  17. }  
  18. listView1.Items.Clear();  
  19. //Subheader  
  20. listView1.Items.Add("Status");  
  21. foreach (DataRow row in dt.Rows)  
  22. {  
Thank you. 

Answers (1)