Listbox DataSource

G

Guest

First my apologies, this may be longer than the normal question.

I have a windows app (.NET 2.0, VS2005), and I've written a user control
that will allow the user to "drag and drop" a directory from one computer
(files are in NVM), to another (files on a PCMIA memory card). The actual
directory names are meaningless to the user, so we display a data item and a
datetime that the directory was created. When I fill the listbox that is the
target, I create a class that has the "displayed" information and the real
directory name, load instances of those classes into an ArrayList and use
that as the DataSource of the listbox. Here is the code for the class:
public class RMMDisplayClass
{
private string pvtRMMListDirectory;
private string pvtRMMDirectoryInfo;

public RMMDisplayClass(string strListDirectory, string
strRMMFullDirectory)
{
this.pvtRMMListDirectory = strListDirectory;
this.pvtRMMDirectoryInfo = strRMMFullDirectory;
}

public string RMMListDirectory
{
get
{
return pvtRMMListDirectory;
}
set
{
this.pvtRMMListDirectory = value;
}
}

public string RMMFullDirectory
{
get
{
return pvtRMMDirectoryInfo;
}
set
{
this.pvtRMMDirectoryInfo = value;
}
}
}

When I enter the control I have a method that loads all the directories that
are already present on the RMM into an ArrayList, then use that as the
DataSouce for the listbox, and that works fine. HOWEVER, when I do the copy,
it does the copy routine and then I run the same method to "reload" the
listbox to show the copied directory. BUT it does not show up. I clear the
ArrayList, but the copied directory does not appear. If I shut down and
restart it shows up in the list.

I have found a workaround, by setting the DataSource property of the listbox
to null, then clearing the listbox, then resetting the DataSource back to the
ArrayList, but this seems awfully kludgy as they say. Here is the code where
I reset the list box (without workaround).

public void DisplayRMMDirectories()
{
string lstItem = "";
RMMDirectories.Clear();
string[] RMMDirectoryList = myRMMData.GetRMMDataDirectories();
foreach (string strRMMDir in RMMDirectoryList)
{
try
{
DirectoryInfo di = new DirectoryInfo(strRMMDir + @"\Forms
Data");
RMMDataTransfer.RMMDataTransfer.FileDirectoryIdInfo idInfo;
idInfo =
RMMDataTransfer.RMMDataTransfer.GetFileDirectoryIdInfo(di);
rmmTailNumber = idInfo.TailNumber;
rmmFlightDate = idInfo.TakeoffTime.ToString("yyyy-MM-dd
HH:mm:ss");
lstItem = rmmTailNumber + " " + rmmFlightDate;

RMMDirectories.Add(new RMMDisplayClass(lstItem, strRMMDir));
di = null;
}
catch (FileNotFoundException exp)
{
//MessageBox.Show(exp.ToString());
}
catch (Exception exp)
{
Debug.WriteLine(exp.ToString());
}
}
if (RMMDirectories.Count > 0)
{
lstRMMFiles.DataSource = RMMDirectories;
lstRMMFiles.DisplayMember = "RMMListDirectory";
lstRMMFiles.ValueMember = "RMMFullDirectory";
lstRMMFiles.Refresh();
}
}
Anyone got any ideas on why this is working this way, and how to fix other
than my workaround?

TIA
WhiteWizard
aka Gandalf
MCSD.NET, MCAD, MCT
 
O

Otis Mukinfus

On Thu, 28 Sep 2006 10:00:02 -0700, WhiteWizard

[snip]
When I enter the control I have a method that loads all the directories that
are already present on the RMM into an ArrayList, then use that as the
DataSouce for the listbox, and that works fine. HOWEVER, when I do the copy,
it does the copy routine and then I run the same method to "reload" the
listbox to show the copied directory. BUT it does not show up. I clear the
ArrayList, but the copied directory does not appear. If I shut down and
restart it shows up in the list.

I have found a workaround, by setting the DataSource property of the listbox
to null, then clearing the listbox, then resetting the DataSource back to the
ArrayList, but this seems awfully kludgy as they say.
[snip]

That's they way I've always done it.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top