Messagebox displaying without being called

S

shawn.yu

When a certain line of code is called, a messagebox is displayed to the user
with the message "Conversion from type 'DataRowView' to type 'Integer' is not
valid.". The strange thing is that I am not telling a messagebox to be
displayed (I am not calling MessageBox.Show or anything similar). No
exception is thrown. The line of code is still executed successfully.

Here is the method:

Public Shared Sub PopulateMonthDropDown(ByVal cboMonth As ComboBox, ByVal
month As Integer)
Dim dt As DataTable = New DataTable("month")

dt.Columns.Add("monthcode", GetType(Integer))
dt.Columns.Add("monthstring", GetType(String))

dt.Rows.Add(New Object() {1, "January"})
dt.Rows.Add(New Object() {2, "February"})
dt.Rows.Add(New Object() {3, "March"})
dt.Rows.Add(New Object() {4, "April"})
dt.Rows.Add(New Object() {5, "May"})
dt.Rows.Add(New Object() {6, "June"})
dt.Rows.Add(New Object() {7, "July"})
dt.Rows.Add(New Object() {8, "August"})
dt.Rows.Add(New Object() {9, "September"})
dt.Rows.Add(New Object() {10, "October"})
dt.Rows.Add(New Object() {11, "November"})
dt.Rows.Add(New Object() {12, "December"})

cboMonth.DataSource = dt 'Message is dispalyed here
cboMonth.DisplayMember = "monthstring"
cboMonth.ValueMember = "monthcode"
cboMonth.SelectedValue = month
End Sub

As per the comment, the messagebox is displayed when I call
cboMonth.DataSource = dt. What can cause message boxes to be displayed
without directly telling them to?
 
S

shawn.yu

Thank you Patrice.

It was the handler. I didn't realize my developer had added code to the
handler. On top of that neither of us realized the event "Handles
cboMonth.SelectedIndexChanged" was being trigged just when the form was
loading even before our code had a chance to bind data to the drop down menu
items. So we go the strange messagebox because it was an error. It just
surprised us that the "try catch" block wasn't able to "catch" it as an
exception.

Anyways your look at the event idea lead us to the root caused and we fixed
it. thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top