Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i had listed .doc files in a listbox using "folderbrowserdialog" , now i need to merge the .doc files to a single .doc file.

i need the procedure to assign the listbox items(.doc files) to a object , so that i can call the files in a object and then read it finally for merging ...

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       flb.RootFolder = Environment.SpecialFolder.MyComputer
       flb.ShowNewFolderButton = False
       Dim result As DialogResult = flb.ShowDialog
       If (result = DialogResult.OK) Then
           ListBox1.Items.Clear()
           TextBox1.Text = flb.SelectedPath
           For Each filename In Directory.GetFiles(flb.SelectedPath, "*.doc").Union(Directory.GetFiles(flb.SelectedPath, "*.rtf").ToArray())
               ListBox1.Items.Add(Path.GetFileName(filename))
     Next
       End If
   End Sub
Posted

1 solution

You don't have to add objects of the type string to the list box Items — they can be of any type. More than that, I recommend to use some semantically descriptive types instead of strings, as you will likely need some information on the item when you work with its selection, etc.

It leaves just for one problem: what text will be displayed in the items? The solution is simple: in the type of the item, override the method ToString as the value returned by this function is the value shown in the list box.

Problem solved.

[EDIT]

Please see my past answer where I complied several past answers on related problems, with source code samples applicable to ComboBox and ListBox:
combobox.selectedvalue shows {} in winform[^].

—SA
 
Share this answer
 
v2
Comments
ANANTH P 14-Nov-11 3:05am    
the contents in the listbox are documnets files , to read the document files in the listbox items i have to assign it as object. so kindly give idea for this
Sergey Alexandrovich Kryukov 6-Feb-13 13:46pm    
Please see my updated answer, after [EDIT].
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900