home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 23 web forms and controls / databinding / functions.vb < prev    next >
Encoding:
Text File  |  2002-01-03  |  1.4 KB  |  43 lines

  1. Module Functions
  2.     ' Return the index in a ListControl given a value.
  3.     Function GetIndexFromValue2(ByVal lst As ListControl, ByVal value As String) As Integer
  4.         Dim i As Integer
  5.         For i = 0 To lst.Items.Count - 1
  6.             If lst.Items(i).Value = value Then
  7.                 ' we've found the element
  8.                 Return i
  9.             End If
  10.         Next
  11.         ' else return not found
  12.         Return -1
  13.     End Function
  14.  
  15.     ' Select the ListControl element with a given value.
  16.     Sub SelectItemFromValue(ByVal lst As ListControl, ByVal value As String)
  17.         Dim i As Integer
  18.         For i = 0 To lst.Items.Count - 1
  19.             If lst.Items(i).Value = value Then
  20.                 ' we've found the element - select it and exit.
  21.                 lst.SelectedIndex = i
  22.                 Exit Sub
  23.             End If
  24.         Next
  25.     End Sub
  26.  
  27.     ' Find a control in a hierarchy of controls.
  28.     Function FindControlRecursive(ByVal ctrl As Control, ByVal id As String) As Control
  29.         ' Exit if this is the control we're looking for.
  30.         If ctrl.ID = id Then Return ctrl
  31.  
  32.         ' Else, look in the hiearchy.
  33.         Dim childCtrl As Control
  34.  
  35.         For Each childCtrl In ctrl.Controls
  36.             Dim resCtrl As Control = FindControlRecursive(childCtrl, id)
  37.             ' Exit if we've found the result
  38.             If Not resCtrl Is Nothing Then Return resCtrl
  39.         Next
  40.     End Function
  41.  
  42.  
  43. End Module