Arnold Zurbito Arnold Zurbito - 3 months ago 20
Vb.net Question

Is there any way to hide a MessageBox?

Is there any way to hide a MessageBox at form load?

I have used

Checkedlistbox
, and already there is a
checkeditems
on load of a
Form2
.

What I want to do is, when I click
Form1
it shows
Form2
with
Checkedlistbox
. My problem is, when I click
Form1
, it show up MessageBox before
Form2
.

Here is my code on vb.net:

On
Form1
:

Private Sub cmdSubmitModifyQuant_Click(sender As Object, e As EventArgs) Handles cmdSubmitModifyQuant.Click
Form2.Show()
End Sub


On
Form2
:

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
chklstBox1Fill()
End Sub

Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
If e.NewValue = CheckState.Checked Then
question = MsgBox("Area you sure you want to remove?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Message")
If question = MsgBoxResult.Yes Then
'Nevermind
ElseIf question = MsgBoxResult.No Then
e.NewValue = CheckState.Checked
End If
End If
End Sub


In my code you can see that i also need to check
checklistbox1
.

Answer

This issue is probably that inside the chklstBox1Fill method you are checking items in your check box list, this causes the event to raise that shows the checkbox. One way to avoid this would be to set a flag to indicate you are populating the list and not show the message box when the flag is set:

Private FillingList As Boolean

Private Sub chklstBox1Fill()
    FillingList = True

    'Rest of method here.

    FillingList = False
End Sub

Private Sub CheckedListBox1_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
    If FillingList = True Then
        Return
    End If

    If e.NewValue = CheckState.Checked Then
      question = MsgBox("Area you sure you want to remove?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Message")
        If question = MsgBoxResult.Yes Then
           'Nevermind
        ElseIf question = MsgBoxResult.No Then
          e.NewValue = CheckState.Checked
        End If
    End If
End Sub

(Forgive my VB.Net, been several years since I wrote any!)

Comments