Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class.cs
C#
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;
                }
            }
        }
    }
}

and I wish to put in Form1.cs the list in listview by columns[zbor,airport,company], but I don't now how
C#
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));

                }
        }

can someone help me, please?
Posted

1 solution

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
 
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