Click here to Skip to main content
14,927,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I am working with c# and winforms. now i want to add multiple values in multiple columns.

my default listview columns are must be based on the date. like below
C#
DateTime today=DateTime.Today;
lvAvailableRooms.View = View.Details;
lvAvailableRooms.LabelEdit = false;
lvAvailableRooms.GridLines = true;
lvAvailableRooms.Columns.Add(today.ToShortDateString(), 80);
lvAvailableRooms.Columns.Add(today.AddDays(1).ToShortDateString(), 80);
.
.
.
lvAvailableRooms.Columns.Add(today.AddDays(10).ToShortDateString(), 80);


my Database query will be like this

SQL
lvAvailableRooms.Items.Clear();
for (int k = 0; k < lvAvailableRooms.Columns.Count; k++)
{
dt = conn.dataTable("select room_numbers as RoomNumber from room_number where room_status='Available' and room_numbers not in (select room_number from room_no_info where '" + lvAvailableRooms.Columns[k].Text + "' between in_date and out_date and stay_status='N/A')");

foreach (DataRow data in dt.Rows)
{
ListViewItem item = new ListViewItem(data[0].ToString());

lvAvailableRooms.Items.Add(item);
}
}



but it shows all values in first row itself....
can you anyone help me?
Posted
Updated 3-Jul-13 0:33am
v2

1 solution

Problem is that you are not adding new row to the ListView.Items collection.


listView1.Items.Add(row);



if (dt.Rows.Count > 0)
  {
   ListViewItem row = new ListViewItem();
   for (int i = 0; i < dt.Rows.Count; i++)
   {
     row.SubItems.Add(dt.Rows[i][0].ToString());
   }

listView1.Items.Add(row);
  }
   
Comments
Balasubramanian T 29-Jun-13 5:54am
   
thank u...but it not working fine....i want view the records in date wise..can u help me dude???
Mahesh Bailwal 29-Jun-13 10:56am
   
you need to sort your data by date before adding it to listView. Any issue in that?

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