Question Modal Form Problem

dfenton21

Member
Joined
Apr 26, 2011
Messages
20
Programming Experience
Beginner
I have the following routine in a form's load event

VB.NET:
[COLOR=blue]Public[/COLOR] [COLOR=blue]Sub[/COLOR] frmAddBooking_Load([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] System.Object, [COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.EventArgs) [COLOR=blue]Handles[/COLOR] [COLOR=blue]MyBase[/COLOR].Load

  dtemp = employees.PopulateBox

  lstEmployees.View = View.Details
  lstEmployees.GridLines = [COLOR=blue]False[/COLOR]
  lstEmployees.FullRowSelect = [COLOR=blue]True[/COLOR]
  lstEmployees.HideSelection = [COLOR=blue]False[/COLOR]
  lstEmployees.MultiSelect = [COLOR=blue]False[/COLOR]

  [COLOR=blue]Call[/COLOR] clspopulate.PopulateLstEmployees(dtemp)

 [COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
The PopulateLstEmployees in the clsPopulate class is:

VB.NET:
[COLOR=blue]Public[/COLOR] [COLOR=blue]Sub[/COLOR] PopulateLstEmployees([COLOR=blue]ByVal[/COLOR] dtemp [COLOR=blue]As[/COLOR] DataTable)

  [COLOR=blue]Dim[/COLOR] foundemps() [COLOR=blue]As[/COLOR] DataRow
  [COLOR=blue]Dim[/COLOR] search [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR]

  frmAddBooking.lstEmployees.Clear()

  search = frmAddBooking.txtFilter.Text

  foundemps = dtemp.[COLOR=blue]Select[/COLOR]([COLOR=#a31515]"StaffName LIKE '"[/COLOR] & search & [COLOR=#a31515]"*'"[/COLOR])

  frmAddBooking.lstEmployees.Columns.Add([COLOR=#a31515]"Staff No"[/COLOR], 70)
  frmAddBooking.lstEmployees.Columns.Add([COLOR=#a31515]"Name"[/COLOR], 171)
  frmAddBooking.lstEmployees.Columns.Add([COLOR=#a31515]"Department"[/COLOR], 171)

  [COLOR=blue]For[/COLOR] i = 0 [COLOR=blue]To[/COLOR] foundemps.GetUpperBound(0)
   [COLOR=blue]Dim[/COLOR] lvi [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] ListViewItem

   lvi.Text = foundemps(i)(0).ToString
   lvi.SubItems.Add(foundemps(i)(1).ToString)
   lvi.SubItems.Add(foundemps(i)(2).ToString)
   frmAddBooking.lstEmployees.Items.Add(lvi)
  [COLOR=blue]Next[/COLOR] i


  frmAddBooking.lbl1.Text = [COLOR=#a31515]"Employees Found: "[/COLOR] & foundemps.[COLOR=blue]Count[/COLOR]

  MsgBox(foundemps.[COLOR=blue]Count[/COLOR])

 [COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
I would expect the listview to be populated and the label's text to be changed.
However, when I run the code, the listview isn't populated and the label's text property isn't changed.I added that msgbox at the end to check if the datatable was correctly passed from the load event, and it is.

frmAddBooking is a modal form. If I didn't show the form modally, the controls update with the data perfectly.
The form needs to be modal, so my question is obviously why is the modal status affecting the outcome of the PopulateLstEmployees routine, and how can I rectify it. The code I'm using to show frmAddBooking is:


VB.NET:
[COLOR=Blue]Dim[/COLOR] frm [COLOR=Blue]as[/COLOR] [COLOR=Blue]New[/COLOR] frmAddBooking

[COLOR=Blue]If[/COLOR] frm.ShowDialog = DialogResult.OK [COLOR=Blue]Then[/COLOR]
   frm.Dispose()
[COLOR=Blue]End[/COLOR] [COLOR=Blue]If[/COLOR]

I would really appreciate someone's assistence with this.
Thanks
 
Back
Top