tags:

views:

1022

answers:

2

Hi,

I have 3 controls in a WPF window.. a textbox, listbox and listview.

The textbox is like a searching textbox, where i search for Folder's in a particular folder, the list of searched folders will be displayed in listbox. I am able to do until this part.

Now, if I select any of the displayed folders in the listbox, then the files available in the particular folder should be displayed in the ListView. (missing out the link b/w the 2 here).

eg : I have 3 folders displayed in listbox (say folder1, folder2, folder3).each folder has few excel files. I selected folder 2 ( which has 5 excel files, mark.xls, steve.xls, cary.xls, rick.xls and jenny.xls and also a subfolder inside that called Launch1).

Now, the List view should show the folder2 contents divided into 3 columns, ( col1, col2, col3).

Name                           Desc                                      Date

--------------------------------------------------------------------------------

Mark                     this is mark's excel                         07/20/2009

steve                    this is steve's excel.                       07/22/2009

cary                     .....................                        ..........

rick                     .....................                        ..........

jenny                    .....................                        ..........

--------------------------------------------------------------------------------

+ Launch1

Again Launch1 folder might have few workbooks, so I have put a plus on it.. so when + is clicked.. it shuold display the files inside this folder.

I am using Xaml and C#... please help.

Now, the problem I am facing is.. if I search for the files which i have to display... I am able to get the files while debugging..( using Add watch..) , but I was not able to add the data to the ListView...

Thank You,

Ramm

A: 

Hi,, Please look at the xaml code here

<ListView Name="lstviewOfOwners" Grid.Row="0" Height="150" Width="1020" HorizontalAlignment="Left" >
  <ListView.View>
    <GridView >
     <GridViewColumn Header="WorkBook" Width="270" DisplayMemberBinding="{Binding AnyWorkbook}" />
     <GridViewColumn Header="Description" Width="550" DisplayMemberBinding="{Binding DescName}" />
     <GridViewColumn Header="Date" Width="200" DisplayMemberBinding="{Binding WorkbookDate}" />
    </GridView>
  </ListView.View>
</ListView>

Now, the problem I am facing is.. if I search for the files which i have to display... I am able to get the files while debugging..( using Add watch..) , but I was not able to add the data to the ListView...

private void btnUploadButton_Click(object sender, RoutedEventArgs e)
    {
        if (txtBxUploadTB.IsVisible)
        {

        lstviewOfOwners.Items.Add(// here I have to add the files present in a particular folder in the local hard drive);

    }

Please help me Thanks Ramm

Aditya
+2  A: 

You can use an anonymous type to get the job done:

private void btnUploadButton_Click(object sender, RoutedEventArgs e) {
  if (txtBxUploadTB.IsVisible) {
    var files = System.IO.Directory.GetFiles("C:\\"); // just an example
    foreach (string file in files) {
      // I used dummy values, modify as appropriate
      lbFolders.Items.Add(new { AnyWorkbook = file, DescName = "descr", WorkbookDate = DateTime.Now });
    }
  }
}
Julien Poulin
Julien,Thanks for the answer.. it solved a bit for me..how to make the appearance in ListView as hierarchial view??I mean, i have main folder (called Download).. it has subfolders called launch1(this has 5 excel files inside), launch2(this has 6 excel files), launch3(this 3 excel files) each.so, when i load it thro the btnUploadButton_Click ( said above post). I like to have in a hierarchial way and I should be able to select the any excel file in any of the 3 folders.. which should open the excel file. when i provide the path to the btnUpload it will have the 3 foldersPls helpme
Aditya