In a Visual basic.net 2010 desktop application, I am loading a list of Access 2013 files that the user needs to select to work with. The code listed below is correct but the file names are too long for the combo box.
Here is the code:
Try
Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")
Dim dir As String
For Each dir In dirAccessFiles
cboAccessFile.Items.Add(dir)
Next
Catch except As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
Thus I have the following questions to ask you:
1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that?
2. Right now in dropdownlist box, the values look like,
'H:\Testfiles\Diane__Currentyear.accdb'.
I would like the value only of 'Diane__Currentyear' that is listed above to display. Also where hardcoded value of 'H:\Testfiles' is displayed in the code above, I will get the actual value from the app. config file.
Thus would you show the code on how to display only the value of 'Diane__Currentyear' in the list of combo box values?
Manoj BhoirPosted Jun 9, 2015, 5:57 AM
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")
Dim dir As String
For Each dir In dirAccessFiles
Dim objComboBoxItem As ComboboxItem = New ComboboxItem
objComboBoxItem.Text = System.IO.Path.GetFileNameWithoutExtension(dir)
objComboBoxItem.Value = dir
ComboBox1.Items.Add(objComboBoxItem)
Next
Catch except As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
Public Class ComboboxItem
Public Property Text As String
Public Property Value As Object
Public Overrides Function ToString() As String
Return Text
End Function
End Class
End Class
Juan MillerPosted Jun 30, 2020, 10:20 AM
Upendra Pratap ShahiPosted Jun 9, 2015, 6:11 AM
For Each dir In dirAccessFiles
Next
Saroj Kumar SahuPosted Jun 9, 2015, 5:26 AM
For Each dir In dirAccessFiles
cboAccessFile.Items.Add(System.IO.Path.GetFileNameWithoutExtension(dir))
Next
I hope this helps you..