Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to bind sub items in List item in win forms with maximize and minimize buttons c#, i have just bind listitem with multiple columns,here is my code

What I have tried:

C#
listView2.Columns.Add("Id", 245, HorizontalAlignment.Left);
listView2.Columns.Add("Name", 241, HorizontalAlignment.Left);
listView2.Columns.Add("Mobile Number", 245, HorizontalAlignment.Left);
listView2.Columns.Add("ASET", 245, HorizontalAlignment.Left);
// Getting the data to a datasource
SqlConnection con = new SqlConnection("Data Source=192.168.1.101\\SQLEXPRESS;Initial Catalog=algen_db;User ID=vipl-user;Password=vipl-user!@#$%");
listView2.Items.Clear();
SqlDataAdapter adp = new SqlDataAdapter("select acdesc,acno,speactype,acremarks from chartaccount where ParentAcNo is null order by AcNo", con);
DataTable dt = new DataTable();
adp.Fill(dt);

string[] Str = new string[4];
ListViewItem newItm;
foreach (DataRow dataRow in dt.Rows)
{
    Str[0] = dataRow["acdesc"].ToString();
    Str[1] = dataRow["acno"].ToString();
    Str[2] = dataRow["speactype"].ToString();
    Str[3] = dataRow["acremarks"].ToString();
    newItm = new ListViewItem(Str);
    listView2.Items.Add(newItm);              
    newItm.SubItems.Add("Aaa");
}
Posted
v2

1 solution

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