ListView in C#
-
"Ella Pugazhum iraivan oruvanukkae"
Have a Happy Coding.....
-
Hi mrithula.... I have personally checked the below code and its working properly in my machine....
DirectoryInfo di = new DirectoryInfo(fbd.SelectedPath);
if (di.Exists)
{
String[] files;
files = Directory.GetFiles(fbd.SelectedPath);
foreach (string file in files)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = file;
lvi.ImageIndex = 0;
listView1.Items.Add(lvi);
}
}If it shows any error let me know....
Have a Happy Coding.....
Hi I am able to list all the exe files in listView control.If the 1st exe has started i want to set the status of the ist sub item to "Started"
foreach(Process pr in proclist)
{
String proname = pr.ProcessName;
//listBox4.Items.Add(proname);
lvsi=new ListViewItem.ListViewSubItem();
lvsi.Text="Started...";
lvi.SubItems.Add(lvsi);
}int b = proclist.Count; listBox4.Items.Add(b.ToString());
proclist contains the list of all exe that have started.Currently there is only 1 exe(i.e the 1st one in the listview control).I want to display started to the 1st subitem.The above code that im using displays "started" as the last sub item.How can i change this?
-
Hi I am able to list all the exe files in listView control.If the 1st exe has started i want to set the status of the ist sub item to "Started"
foreach(Process pr in proclist)
{
String proname = pr.ProcessName;
//listBox4.Items.Add(proname);
lvsi=new ListViewItem.ListViewSubItem();
lvsi.Text="Started...";
lvi.SubItems.Add(lvsi);
}int b = proclist.Count; listBox4.Items.Add(b.ToString());
proclist contains the list of all exe that have started.Currently there is only 1 exe(i.e the 1st one in the listview control).I want to display started to the 1st subitem.The above code that im using displays "started" as the last sub item.How can i change this?
when you add the subitem for an item in the listview the sequence starts always from left to right. Not sure what mistake you are doing. But you can try this... To add the subitem, for the STATUS column header, use the same item object which you used to add to the listview control. i.e. if item 1 in the Server header is added by using lvi then,
ListviewItem lvi = new ListViewItem();
lvi.SubItem.Add("Started");
ListView.Items.Add(lvi);This should work i believe.
Have a Happy Coding.....
-
when you add the subitem for an item in the listview the sequence starts always from left to right. Not sure what mistake you are doing. But you can try this... To add the subitem, for the STATUS column header, use the same item object which you used to add to the listview control. i.e. if item 1 in the Server header is added by using lvi then,
ListviewItem lvi = new ListViewItem();
lvi.SubItem.Add("Started");
ListView.Items.Add(lvi);This should work i believe.
Have a Happy Coding.....
-
Hi I tried with this but it displays "Started.." as a subitem for the last item in listview control.I used this code in the button click event of "Start" button which starts the exe file.
okay..... then you may try the SubItem index property, to directly specify which subitem to modify. for example, if you want to change the status of the first server Item, then ServerItem1.SubItems[1].text = "Started";
Have a Happy Coding.....
-
okay..... then you may try the SubItem index property, to directly specify which subitem to modify. for example, if you want to change the status of the first server Item, then ServerItem1.SubItems[1].text = "Started";
Have a Happy Coding.....
-
Hi I tried with this.Is this right?Nothing gets displayed when the exe starts.
int g = lvi.Index;
lvi = new ListViewItem(); if (g == 1) lvi.SubItems\[1\].Text = "Started.."; listView1.Items.Add(lvi);
no this will not work. because you are creating a new lvi.
Have a Happy Coding.....
-
okay..... then you may try the SubItem index property, to directly specify which subitem to modify. for example, if you want to change the status of the first server Item, then ServerItem1.SubItems[1].text = "Started";
Have a Happy Coding.....
-
Hi Can you please tell why it adds "started.." as a sub item for last item?Why does it not display it as the sub item for the 1st item?
Not sure what's the problem.... but instead of this
foreach(Process pr in proclist)
{
String proname = pr.ProcessName;
//listBox4.Items.Add(proname);
lvsi=new ListViewItem.ListViewSubItem();
lvsi.Text="Started...";
lvi.SubItems.Add(lvsi);
}try this foreach(Process pr in proclist) { String proname = pr.ProcessName; //listBox4.Items.Add(proname); lvi.SubItems[1].Text = "started"; } Make it sure that you are executing this code after adding the item to the list view... otherwise you may get an exception in the blocked line.
Have a Happy Coding.....
-
Not sure what's the problem.... but instead of this
foreach(Process pr in proclist)
{
String proname = pr.ProcessName;
//listBox4.Items.Add(proname);
lvsi=new ListViewItem.ListViewSubItem();
lvsi.Text="Started...";
lvi.SubItems.Add(lvsi);
}try this foreach(Process pr in proclist) { String proname = pr.ProcessName; //listBox4.Items.Add(proname); lvi.SubItems[1].Text = "started"; } Make it sure that you are executing this code after adding the item to the list view... otherwise you may get an exception in the blocked line.
Have a Happy Coding.....
-
how many column headers you have??? because the subitems index always starts from 0. can you post the entire code block of the listcontrol??? if possible...
Have a Happy Coding.....
-
how many column headers you have??? because the subitems index always starts from 0. can you post the entire code block of the listcontrol??? if possible...
Have a Happy Coding.....
Hi I have created 3 column headers
private void CreateHeadersAndFillListView()
{
colHead = new ColumnHeader();
colHead.Text = "Servers";
colHead.Width = 250;
listView1.Columns.Add(colHead);colHead = new ColumnHeader(); colHead.Text = "Status"; colHead.Width = 100; listView1.Columns.Add(colHead); colHead = new ColumnHeader(); colHead.Text = "Last accessed"; colHead.Width = 100; listView1.Columns.Add(colHead); } private void PaintList(String sss) { try { //ListViewItem.ListViewSubItem lvsi; reader = new XmlTextReader("path.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Text: //Display the text in each element. // Console.WriteLine(reader.Value); String s1; s1 = reader.Value; String ss; ss = listBox4.SelectedItem.ToString(); sss = ss + s1; object o3 = (object)sss; //String s = (string)o3; //listBox2.Items.Add(o3); DirectoryInfo dire = new DirectoryInfo(sss); if (dire.Exists) { String\[\] folder; folder = Directory.GetDirectories(sss); foreach (string foldername in folder) { DirectoryInfo di = new DirectoryInfo(foldername); if (di.Exists) { String\[\] files; files = Directory.GetFiles(foldername,"\*.exe\*"); foreach (String filename in files) { lvi = new ListViewItem(); lvi.Text = filename; listView1.Items.Add(lvi);
-
how many column headers you have??? because the subitems index always starts from 0. can you post the entire code block of the listcontrol??? if possible...
Have a Happy Coding.....
Hi, If i add subitem like the following it just gives the subitem "Started" corresponding to every item in listview.But what i require is that when the server starts it must display the subitem "Started.." to the corresponding item (server) that has started.
DirectoryInfo di = new DirectoryInfo(foldername);
if (di.Exists)
{
String[] files;
files = Directory.GetFiles(foldername,"*.exe*");foreach (String filename in files) { lvi = new ListViewItem(); lvi.Text = filename; listView1.Items.Add(lvi); lvi = new ListViewItem(); lvi.SubItems.Add("Started.."); listView1.Items.Add(lvi); } this.Controls.Add(listView1);
-
Hi, If i add subitem like the following it just gives the subitem "Started" corresponding to every item in listview.But what i require is that when the server starts it must display the subitem "Started.." to the corresponding item (server) that has started.
DirectoryInfo di = new DirectoryInfo(foldername);
if (di.Exists)
{
String[] files;
files = Directory.GetFiles(foldername,"*.exe*");foreach (String filename in files) { lvi = new ListViewItem(); lvi.Text = filename; listView1.Items.Add(lvi); lvi = new ListViewItem(); lvi.SubItems.Add("Started.."); listView1.Items.Add(lvi); } this.Controls.Add(listView1);
So you finally got that....!!! Hail Hurray!!! If you want to show the status dynamically, then you need to go for threading..... Dedicate a thread specifically for updates and things will work...
Have a Happy Coding.....
-
So you finally got that....!!! Hail Hurray!!! If you want to show the status dynamically, then you need to go for threading..... Dedicate a thread specifically for updates and things will work...
Have a Happy Coding.....
Hi I tried with the following code. It displays "Started" as a subitem for the 2nd item in listview control
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = "Started..";
//lvi.SubItems.Add(lvsi);
listView1.Items[1].SubItems.Insert(1, lvsi);If i use
listView1.Items[0].SubItems.Insert(0, lvsi);
it displys "started " as an item and not a subitem like Server status Last accessed started Server1.exe ... .... Can you give me some suggestions