By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 2,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Listbox DataSource

P: n/a
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.FileDirectoryIdInf o idInfo;
idInfo =
RMMDataTransfer.RMMDataTransfer.GetFileDirectoryId Info(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
Sep 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Thu, 28 Sep 2006 10:00:02 -0700, WhiteWizard
<Wh*********@discussions.microsoft.comwrote:

[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
Sep 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.