Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to add a combo box in a list view at a particular column.

my code:
C#
 private void button1_Click(object sender, EventArgs e)
        {
            using (cmd = new SqlCommand("sp_mstRole", con))
            {
                if (con.State == ConnectionState.Closed)
                    con.Open();
                cmd.CommandType = CommandType.StoredProcedure;


	
                cmd.Parameters.AddWithValue("@RoleName", "");
                cmd.Parameters.AddWithValue("@SiteCode", "Head");
              
                cmd.Parameters.AddWithValue("@Mode", "F");
                cmd.Parameters.AddWithValue("@id", "");
              
                ds = new DataSet();
                da = new SqlDataAdapter(cmd);
                ds.Clear();
                da.Fill(ds);


                if (ds.Tables[0].Rows.Count > 0)
                {

                    for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                        listView1.Columns.Add(ds.Tables[0].Columns[i].ColumnName.ToString(), listView1.Width / 6 - 1);

                }
                listView1.Columns.Add("Control", listView1.Width / 6 - 1);

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ListViewItem row = new ListViewItem(ds.Tables[0].Rows[i][0].ToString());
                    for (int j = 1; j < ds.Tables[0].Columns.Count; j++)
                    {
                        row.SubItems.Add(ds.Tables[0].Rows[i][j].ToString());
                       
                    }
                    row.SubItems.Add("controls");
                    listView1.Items.Add(row);
                    
                }
            }
}

It is working fine but I want to add the combo box at the last column of the list view.
Posted
Updated 24-Jan-14 6:55am
v2

1 solution

Hello my friend,
use the search first.

Reusable ListView in C# with textbox and combobox[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900