Check if Listbox contains nothing

smiles

Well-known member
Joined
May 21, 2008
Messages
47
Programming Experience
Beginner
I have two listbox, one show root folders, and one show child folders of each root folder when navigating between these root folders
If at one root folder, inside it has no child folders then enable createFolderBtn
and vice versa, here is my code
VB.NET:
    Private Sub rootLst_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rootLst.SelectedIndexChanged
        Dim di As New IO.DirectoryInfo("E:\" + rootLst.SelectedItem.ToString)
        Dim dirs As DirectoryInfo() = di.GetDirectories("*" & childName & "*", SearchOption.TopDirectoryOnly)
        childLst.DataSource = dirs
        If dirs Is Nothing Then
            createFolderBtn.Enabled = True
        Else
            createFolderBtn.Enabled = False
        End If
    End Sub
I have rootLst datasource is results of folder with folder's name contains search word.
tested some but the createFolderBtn is disabled always although childLst contains nothing :confused:
Could you help me with that, thanks !!!
 
Hi! Got it :D
VB.NET:
        If dirs.GetLength(0) = 0 Then
            createFolderBtn.Enabled = True
        ElseIf dirs.GetLength(0) > 0 Then
            createFolderBtn.Enabled = False
        End If
 
VB.NET:
createFolderBtn.Enabled = (dirs.GetLength(0) = 0)
What this does is if dirs.GetLength(0) is equal to 0 which produces a boolean and that boolean gets assigned to the createFolderBtn.Enabled property.
 
Customize text in listbox

Nice !!! I will take that very short code :D
Now could you help me with another problem ?
for example:
ListBox1.Items.Add("here for test")
And it will appear in that listbox
here for test
Now how can I customize that text to have something like:
here for test
Bold appears on "for", for e.g
Thanks so much :)
 
You'll need to draw the item's in the list yourself by using the Listbox's DrawItem event or by overriding the OnDrawItem event in a custom control that inherits listbox.

Here's one place to start: Owner drawn ListBox control in VB.NET

I've also recently made a ColorComboBox control and it's posted on this forum where I draw the names of colors next to a box that shows that color in the combo's OnDrawitem overridden event, which is the same event for a ListBox, it may help.
 
Back
Top