My problem.
This is code.
listView1.Columns.Add("Col1");
listView1.Columns.Add("Col2");
string[] strArrGroups = new string[3] { "FIRST", "SECOND", "THIRD" };
string[] strArrItems = new string[4] { "one", "two", "tri", "cetiri" };
for (int i = 0; i < strArrGroups.Length; i++)
{
int groupIndex = listView1.Groups.Add(new ListViewGroup(strArrGroups[i], HorizontalAlignment.Left));
for (int j = 0; j < strArrItems.Length; j++)
{
ListViewItem lvi = new ListViewItem(strArrItems[j]);
lvi.SubItems.Add("Hasta la Vista, Mon Cherri!");
listView1.Items.Add(lvi);
listView1.Groups[i].Items.Add(lvi);
}
}
I dont now how to include new column and write in new column
new srting[] strArrPrimer = {"1","2","3","4"}
Thanks for help
Loading

Upamanyu Roy Choudhury146 reputationPosted Feb 19, 2013, 9:06 AM EST
We can do it in many ways but I did it the way you wrote it.
listView1.Columns.Add("Col1");
listView1.Columns.Add("Col2");
string[] strArrGroups = new string[3] { "FIRST", "SECOND", "THIRD" };
string[] strArrItems = new string[4] { "one", "two", "tri", "cetiri" };
for (int i = 0; i < strArrGroups.Length; i++)
{
int groupIndex = listView1.Groups.Add(new ListViewGroup(strArrGroups[i], HorizontalAlignment.Left));
for (int j = 0; j < strArrItems.Length; j++)
{
ListViewItem lvi = new ListViewItem(strArrItems[j]);
lvi.SubItems.Add("Hasta la Vista, Mon Cherri!");
listView1.Items.Add(lvi);
listView1.Groups[i].Items.Add(lvi);
}
}
//Newly added code for the new column
listView1.Columns.Add("NewColumn");
listView1.Groups.Add(new ListViewGroup("FOURTH", HorizontalAlignment.Left));
string[] strArrPrimer= new string[] {"1","2","3","4"};
for (int j = 0; j < strArrItems.Length; j++)
{
ListViewItem lv = new ListViewItem(strArrPrimer[j]);
listView1.Items.Add(lv);
listView1.Groups[3].Items.Add(lv);
}
If you run it you will see the output and column4 is bening added to the list.
If you find this post as useful please mark it as an answer
sasa lazic95 reputationPosted Feb 19, 2013, 9:15 AM EST
But, must be one but.
Maybe i dont explain correctly what i wont.
i nedd new column thets ok.
and i want write string 1,2,3,4 in new column
now new srting[] strArrPrimer = {"1","2","3","4"}
write like new group
thanks again
Upamanyu Roy Choudhury146 reputationPosted Feb 19, 2013, 9:29 AM EST
How do you want them to look like??
Upamanyu Roy Choudhury146 reputationPosted Feb 19, 2013, 9:33 AM EST
FOUR
-------------------------------------------------
1 2 3 4
sasa lazic95 reputationPosted Feb 19, 2013, 9:39 AM EST
And i want in clo3 insert new srting[] strArrPrimer = {"1","2","3","4"}
thanks again
Example:
col1 col2 col3
frst--------------------
bla bla blA
bla bla blA
bla bla blA
bla bla blA
SECOND----------------
bla bla blA
bla bla blA
bla bla blA
bla bla blA
THIRD----------------
bla bla blA
bla bla blA
bla bla blA
bla bla blA
FOURT----------------
bla bla blA
bla bla blA
bla bla blA
bla bla blA
FIVE----------------
bla bla blA
bla bla blA
bla bla blA
bla bla blA
Upamanyu Roy Choudhury146 reputationPosted Feb 19, 2013, 10:05 AM EST
In a particular group say in group 3 traverse with the for loop , select the items and replace it with 1,2,3,4 or you can create a new group and insert it.
Try it in your own and keep me posted.
sasa lazic95 reputationPosted Feb 21, 2013, 4:59 AM EST
what i want again
I want make listView with group
this is my code
string[] strArrGroups = new string[3] { "ZERO", "SECOND", "THIRD" };
int groupIndex = listView1.Groups.Add(new ListViewGroup(strArrGroups[0], HorizontalAlignment.Left));
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = false;
//Add column header
listView1.Columns.Add("XXXXXXXXX", 70);
listView1.Columns.Add("YYYYYYYY", 70);
listView1.Columns.Add("ZZZZZZZZZ", 70);
listView1.Columns.Add("DDDDDDDD", 70);
//Add items in the listview
string[] arr = new string[4];
ListViewItem itm;
//Add first item
arr[0] = "product_1";
arr[1] = "100";
arr[2] = "10";
arr[3] = "to care";
itm = new ListViewItem(arr);
listView1.Items.Add(itm);
//listView1.Items[0].Group = listView1.Groups[0];
listView1.Groups[0].Items.Add(itm);
//Add second item
arr[0] = "product_2";
arr[1] = "200";
arr[2] = "20";
arr[3] = "to care";
itm = new ListViewItem(arr);
listView1.Items.Add(itm);
//listView1.Items[1].Group = listView1.Groups[1];
listView1.Groups[1].Items.Add(itm);
when i run listview show me frst group default????
but in a second gropu show group ZERO.
I want frst gropu ZERO input in columns arr[0] to arr[3] (produst1,100,10,to care)
after that new gropu SECON and in this group i want to see arr[0] to arr[3] (produst2,200,20,to care)
thanks
sasa lazic95 reputationPosted Feb 21, 2013, 8:11 AM EST
//listView1.View = View.Details;
//listView1.GridLines = true;
//listView1.FullRowSelect = false;
////Add column header
//listView1.Columns.Add("XXXXXXXXX", 70);
//listView1.Columns.Add("YYYYYYYY", 70);
//listView1.Columns.Add("ZZZZZZZZZ", 70);
//listView1.Columns.Add("DDDDDDDD", 70);
////Add items in the listview
//string[] arr = new string[4];
//ListViewItem itm;
////Add first item
//arr[0] = "product_1";
//arr[1] = "100";
//arr[2] = "10";
//arr[3] = "to care";
//itm = new ListViewItem(arr);
//listView1.Items.Add(itm);
////listView1.Items[0].Group = listView1.Groups[0];
//listView1.Groups[0].Items.Add(itm);
////Add second item
//arr[0] = "product_2";
//arr[1] = "200";
//arr[2] = "20";
//arr[3] = "to care";
//itm = new ListViewItem(arr);
//listView1.Items.Add(itm);
////listView1.Items[1].Group = listView1.Groups[1];
//listView1.Groups[1].Items.Add(itm);
just add group in ListView Tasks
Thats all