Re: Messagebox displaying without being called
- From: "Patrice" <http://www.chez.com/scribe/>
- Date: Wed, 4 Feb 2009 20:18:42 +0100
#1 Root cause
Use Option Strict On. It should spot possibly conversion error at compile
time rather than at runtime. This is AFAIK the exact text you'll have if you
try to do some code such as :
Dim o As Object=dt.DefaultView(0) ' Get the first DataRowView
Dim i as Integer=CInt(o) ' Should raise the exact error message you get
(translated from French I get the same than yours).
You can enable this file by file if it causes a massive amount of code to
update but this is a good practice so it's likely better to upgrade this
when you have time..
#2 Why this is not seen as an exception
Have you checked if you have a global error handler or which event are
handled on this combobox ? (such as BindingContextChanged, Format etc...)
taht would contain a messagebox statement ?
It could be also a built in error message (especially when the default
formatting happens) but for now I would say rather user code as what you
shown seems legal...
--
Patrice
"shawn.yu" <shawn.yu@xxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de
groupe de discussion : 54C5C49A-55E5-4181-B50B-61E8EAB07267@xxxxxxxxxxxxxxxx
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?
.
- Follow-Ups:
- Re: Messagebox displaying without being called
- From: shawn.yu
- Re: Messagebox displaying without being called
- References:
- Messagebox displaying without being called
- From: shawn.yu
- Messagebox displaying without being called
- Prev by Date: How can I set LVGS_COLLAPSIBLE in ListView control?
- Next by Date: Re: How to Cancel a Cancel Button event
- Previous by thread: Messagebox displaying without being called
- Next by thread: Re: Messagebox displaying without being called
- Index(es):
Relevant Pages
|