I have a ListView that displays some items (it's not important what they are really). However, what IS important is that the items it displays can have a property of "IsEnabled" or not. By default I only want to show the items where IsEnabled is true. I have therefore provided a checkbox for the user to allow him/her to show all the items, enabled or not.
Now, what I want to do is to show the items that are Disabled in red and enabled items in black. The code below works but it just doesn't look right to me. Is there a better way?
The code is called everytime the CheckBox is clicked.
VB Code:
Private Sub GetPackages() Me.Cursor = Cursors.WaitCursor Me.lv_Packages.Items.Clear() Try objAltirisClient = CreateObject("Altiris.AeXNSClient", ComputerName) Catch ex As Exception MessageBox.Show("There was an error connecting to the Altiris Client.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Me.Cursor = Cursors.Default Return End Try objSWDAgent = objAltirisClient.ClientPolicyMgr.ClientAgent("Altiris.SWD") Dim ColAdvertisements As Object = objSWDAgent.Advertisements For Each objAdvert As Object In ColAdvertisements Dim LVI As New ListViewItem LVI.Tag = objAdvert.ID LVI.Text = objAdvert.Name If Me.check_ShowDisabledPackages.Checked = False Then If objAdvert.IsEnabled = 1 Then Me.lv_Packages.Items.Add(LVI) End If Else If objAdvert.IsEnabled = 1 Then Me.lv_Packages.Items.Add(LVI) Else LVI.ForeColor = Color.Red Me.lv_Packages.Items.Add(LVI) End If End If Next End Sub




Reply With Quote