FormUtils.vb

  1. Class FormUtils
  2.  
  3. Public Shared Sub ChequearCajaLista(
  4. ByVal cajaLista As CheckedListBox,
  5. Optional ByVal marcar As Boolean = True
  6. )
  7. For i = 0 To cajaLista.Items.Count - 1
  8. cajaLista.SetItemChecked(i, marcar)
  9. Next
  10. End Sub
  11.  
  12. Public Shared Sub ChequearCajaLista(
  13. ByVal cajaLista As CheckedListBox,
  14. ByVal indices As IEnumerable
  15. )
  16. ChequearCajaLista(cajaLista, False)
  17. For Each indice As Integer In indices
  18. If indice >= 0 And indice < cajaLista.Items.Count Then
  19. cajaLista.SetItemChecked(indice, True)
  20. End If
  21. Next
  22. End Sub
  23.  
  24. Public Shared Function ObtenerIndicesChequeados(
  25. ByVal cajaLista As CheckedListBox
  26. ) As Integer()
  27. Dim lista As New List(Of Integer)
  28. For Each indice As Integer In cajaLista.CheckedIndices
  29. lista.Add(indice)
  30. Next
  31. Return lista.ToArray()
  32. End Function
  33.  
  34. Public Shared Sub MoverArribaSeleccionado(ByVal cajaLista As ListBox)
  35. If cajaLista.SelectedItems.Count = 1 Then
  36. Dim indice As Integer = cajaLista.SelectedIndex
  37. If indice > 0 Then
  38. Dim elemento As Object = cajaLista.SelectedItem
  39. cajaLista.Items.Remove(elemento)
  40. indice -= 1
  41. cajaLista.Items.Insert(indice, elemento)
  42. cajaLista.SelectedIndex = indice
  43. End If
  44. End If
  45. End Sub
  46.  
  47. Public Shared Sub MoverAbajoSeleccionado(ByVal cajaLista As ListBox)
  48. If cajaLista.SelectedItems.Count = 1 Then
  49. Dim indice As Integer = cajaLista.SelectedIndex
  50. If indice < cajaLista.Items.Count - 1 Then
  51. Dim elemento As Object = cajaLista.SelectedItem
  52. cajaLista.Items.RemoveAt(indice)
  53. indice += 1
  54. cajaLista.Items.Insert(indice, elemento)
  55. cajaLista.SelectedIndex = indice
  56. End If
  57. End If
  58. End Sub
  59.  
  60. End Class
  61.  

Proinf.net