Im currently trying to download all the files from my computer and display them in a list view. Im using a foreach statement for this.
However, when the list view updates the UI flickers alot and its really annoying.
Below is my code to update my UI:
if (text.StartsWith("fdrivel§")) //The client sent a list of drives
{
String data = text.Split('§')[1]; //Get the drive listing
LvClear(listView3); //Clear the listView for drives
foreach (String drive in data.Split('\n')) //Loop through the drives
{
if (!drive.Contains("|")) continue; //If incorrect drive, then skip it
String name = drive.Split('|')[0]; //Get the label of the drive (C:, D:, E: etc.)
String size = Convert(drive.Split('|')[1]); //Get the total size of the drive
AddFileCallback(name, size, "N/A", name); //Update the UI
}
}
This then calls an AddFileCallBack Method that does this:
private void AddFileCallback(String name, String size, String crtime, String path)
{
if (this.InvokeRequired) //If we need to invoke
{
addFile callback = new addFile(AddFileCallback); //Create a callback
this.Invoke(callback, new object[] { name, size, crtime, path }); //Invoke the callback
}
else
{
ListViewItem lvi = new ListViewItem
{
Text = name //Set the entry name
}; //Create a new listView item
lvi.SubItems.Add(size); //Set the entry size
lvi.SubItems.Add(crtime); //Set the entry creation time
lvi.SubItems.Add(path); //Set the entry full path
listView3.Items.Add(lvi); //Add the item to the list
listView3.Items[0].Selected = true; //Select the first item of the list
}
}
Is want it to still load each file one at a time in the ui but I don't want it to flicker.
Wondering if someone could help me.
Thankyou in advance.