如何在列表视图中添加特定列的控件? [英] how to add a control in listview at a particular column?

查看:61
本文介绍了如何在列表视图中添加特定列的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在特定列的列表视图中添加一个组合框。



我的代码:

  private   void  button1_Click( object  sender,EventArgs e)
{
使用(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 ]。行.Count > 0
{

for int i = 0 ; i < ds.Tables [ 0 ]。Columns.Count; i ++)
listView1.Columns.Add( ds.Tables [ 0 ]。列[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 ]。行[i] [j] .ToString());

}
row.SubItems.Add( controls );
listView1.Items.Add(row);

}
}
}



工作正常,但我想在最后一栏添加组合框列表视图。

解决方案

你好我的朋友,

首先使用搜索。



C#中带有文本框和组合框的可重用ListView [ ^ ]

I want to add a combo box in a list view at a particular column.

my code:

 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.

解决方案

Hello my friend,
use the search first.

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


这篇关于如何在列表视图中添加特定列的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆