在C#的列中添加到列表视图 [英] Add to listview in columns in C#

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

问题描述

我有一个class.cs

I have a class.cs

namespace Monit_air_fly
{
    class SearchFlyClass
    {
        public Connectdb conObject = new Connectdb();

        public ArrayList GetFly(int tip, string country, string theDate)
        {
            using (var connection = new SqlConnection(conObject.SetConnection()))
            {
                connection.Open();
                String query = "SELECT ...  = @tip";
                
                using (var command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("@tip", tip);
                    var list = new ArrayList();
                    var reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        //MessageBox.Show("Row exist");
                        int cod_zbor = reader.GetOrdinal("cod_zbor");
                        int nume_aeroport = reader.GetOrdinal("nume_aeroport");
                        int nume_companie = reader.GetOrdinal("nume_companie");
                        while (reader.Read())
                        {
                            decimal nr_zbor = reader.GetDecimal(cod_zbor);
                            string aeroport = reader.GetString(nume_aeroport);
                            string companie = reader.GetString(nume_companie);
                            list.Add(nr_zbor);
                            list.Add(companie);
                            list.Add(aeroport);
                        }
                    }
                    reader.Close();
                    connection.Close();
                    return list;
                }
            }
        }
    }
}


我希望按列[zbor,机场,公司]将List1中的列表放到Form1.cs中,但我现在不知道如何


and I wish to put in Form1.cs the list in listview by columns[zbor,airport,company], but I don''t now how

private SearchFlyClass searchFly = new SearchFlyClass();
private ArrayList fly = new ArrayList();
...
private void ShowResultFlySearch(int direction, string country)
        {
                fly = searchFly.GetFly(direction, country);
                for (int count = 0; count < fly.Count; count++)
                {
                    string zbor = fly[0].ToString();
                    string companie = fly[1].ToString();
                    string aeroport = fly[2].ToString();
                    ListViewItem searchlist = new ListViewItem();
                    searchlist.Items.Add(new ListViewItem(elem));

                }
        }


推荐答案

看看 ^ ]

虽然ListView是一个不错的控件,但DataGridView是更适合您的选择.

如果确实要使用ListView,则需要将View属性设置为View.Details,使用Columns集合添加列,然后使用ListViewItem.SubItems集合添加数据.
此处 [
Have a look at DataGridView Filter Popup[^]

While ListView is a nice control, the DataGridView is a more appropriate choice for you purpose.

If you really want to use the ListView you need to set the View property to View.Details, add columns using the Columns collection, and then use the ListViewItem.SubItems collection to add the data.

An example is available here[^]

Best regards
Espen Harlinn


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

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