Programmatically determining selected index of combobox produces null error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Programmatically determining selected index of combobox produces null erro

Below is one example of what I tried. Subsequently I update the database in the submitupdate button. My scheme is adapted from ADO.NET Core Reference Chapters 13 and 11

If I click the combobox to the same values already there, it works fine. That's not such a burden but it seems to me I ought to be able to determine the selected index programmatically

Any help would be appreciated

polynomial5

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Clic
cm.EndCurrentEdit(
If cboPubFreq.SelectedIndex = -1 The
cboPubFreq.SelectedIndex =
ElseIf cboPubFreq.SelectedIndex = cm.Count - 1 The
cboPubFreq.SelectedIndex =
Els
cboPubFreq.SelectedIndex = cboPubFreq.SelectedIndex +
End I
If cboPublicationType.SelectedIndex = -1 The
cboPublicationType.SelectedIndex =
Els
cboPublicationType.SelectedIndex = cboPublicationType.SelectedInde
End I
If cboContentRights.SelectedIndex = -1 The
cboContentRights.SelectedIndex =
Els
cboContentRights.SelectedIndex = cboContentRights.SelectedInde
End I
If cboPointOfView.SelectedIndex = -1 The
cboPointOfView.SelectedIndex =
Els
cboPointOfView.SelectedIndex =
End I
SetEditMode(False
End Sub
 
Polynomial5d:

Which line is throwing the exception? You can check .SelectedIndex
programatically and there isn't one, it will return -1. I'm not sure what's
causing the null reference exception, but the most likely culprits currently
look like one of the two references to 'cm' or whatever happens in the sub
at the bottom. And if I could make a suggestion for future posts, when
using a code snippet this long, there could be a bunch of things that are
potentially wrong. If you step through the debugger and identify the
specific line, it'd definitely be helpful. (In no way am I being critical,
just trying to make a helpful suggestion). Also, (and you can use this in
most other contexts as well), I'd but a bunch of debug.Assertions at the
beginning of my code block. Something is causing a NullReferenceException
and there are only a few objectst that can be doing this if you have
isolated this block as the problem. So, I'd Debug.Assert(!comboBoxName =
null); for instance.

Check the cm for me and we'll figure this bugger out.

Cheers,

Bill

www.devbuzz.com
www.knowdotnet.com
polynomial5d said:
Programmatically determining selected index of combobox produces null error

Below is one example of what I tried. Subsequently I update the database
in the submitupdate button. My scheme is adapted from ADO.NET Core
Reference Chapters 13 and 11.
If I click the combobox to the same values already there, it works fine.
That's not such a burden but it seems to me I ought to be able to determine
the selected index programmatically.
Any help would be appreciated.

polynomial5d

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
 
Bill

I stepped through both the add button click handler and the update button click handler. Both took me on a long trip through the application, starting with sub Main. In the end I didn't get any information. All's that happened is that when I clicked Add, put in a new publication but left the comboboxes alone, and then clicked update, the row appeared in the datagrid with nulls in the columns with comboboxes

when I use Debug.Assert(cboPubFreq = DBNull), I'm told dbnull is a type and cannot be used in an expression. It doesn't like null or system.dbnull, either

sob

polynomial5d

BTW, what does eMVP stand for? Extra? Extraordinary? EventArgumentsMVP?
 
Back
Top