Listbox DataSource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WhiteWizard

    Listbox DataSource

    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 pvtRMMListDirec tory;
    private string pvtRMMDirectory Info;

    public RMMDisplayClass (string strListDirector y, string
    strRMMFullDirec tory)
    {
    this.pvtRMMList Directory = strListDirector y;
    this.pvtRMMDire ctoryInfo = strRMMFullDirec tory;
    }

    public string RMMListDirector y
    {
    get
    {
    return pvtRMMListDirec tory;
    }
    set
    {
    this.pvtRMMList Directory = value;
    }
    }

    public string RMMFullDirector y
    {
    get
    {
    return pvtRMMDirectory Info;
    }
    set
    {
    this.pvtRMMDire ctoryInfo = 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 DisplayRMMDirec tories()
    {
    string lstItem = "";
    RMMDirectories. Clear();
    string[] RMMDirectoryLis t = myRMMData.GetRM MDataDirectorie s();
    foreach (string strRMMDir in RMMDirectoryLis t)
    {
    try
    {
    DirectoryInfo di = new DirectoryInfo(s trRMMDir + @"\Forms
    Data");
    RMMDataTransfer .RMMDataTransfe r.FileDirectory IdInfo idInfo;
    idInfo =
    RMMDataTransfer .RMMDataTransfe r.GetFileDirect oryIdInfo(di);
    rmmTailNumber = idInfo.TailNumb er;
    rmmFlightDate = idInfo.TakeoffT ime.ToString("y yyy-MM-dd
    HH:mm:ss");
    lstItem = rmmTailNumber + " " + rmmFlightDate;

    RMMDirectories. Add(new RMMDisplayClass (lstItem, strRMMDir));
    di = null;
    }
    catch (FileNotFoundEx ception exp)
    {
    //MessageBox.Show (exp.ToString() );
    }
    catch (Exception exp)
    {
    Debug.WriteLine (exp.ToString() );
    }
    }
    if (RMMDirectories .Count 0)
    {
    lstRMMFiles.Dat aSource = RMMDirectories;
    lstRMMFiles.Dis playMember = "RMMListDirecto ry";
    lstRMMFiles.Val ueMember = "RMMFullDirecto ry";
    lstRMMFiles.Ref resh();
    }
    }
    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
  • Otis Mukinfus

    #2
    Re: Listbox DataSource

    On Thu, 28 Sep 2006 10:00:02 -0700, WhiteWizard
    <WhiteWizard@di scussions.micro soft.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


    Comment

    Working...