Re: Programmatically determining selected index of combobox produces null error
From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 05/15/04
- Next message: William Ryan eMVP: "Re: Create own Datalayer or Use LLBLGen Pro"
- Previous message: Ryan: "Create own Datalayer or Use LLBLGen Pro"
- In reply to: polynomial5d: "Programmatically determining selected index of combobox produces null error"
- Next in thread: polynomial5d: "RE: Programmatically determining selected index of combobox produces null error"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 15 May 2004 18:39:13 -0400
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" <anonymous@discussions.microsoft.com> wrote in message
news:E29291EE-5B03-40C8-84DA-0BF0EC953D3C@microsoft.com...
> 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
> cm.EndCurrentEdit()
> If cboPubFreq.SelectedIndex = -1 Then
> cboPubFreq.SelectedIndex = 1
> ElseIf cboPubFreq.SelectedIndex = cm.Count - 1 Then
> cboPubFreq.SelectedIndex = 1
> Else
> cboPubFreq.SelectedIndex = cboPubFreq.SelectedIndex + 1
> End If
> If cboPublicationType.SelectedIndex = -1 Then
> cboPublicationType.SelectedIndex = 1
> Else
> cboPublicationType.SelectedIndex =
cboPublicationType.SelectedIndex
> End If
> If cboContentRights.SelectedIndex = -1 Then
> cboContentRights.SelectedIndex = 1
> Else
> cboContentRights.SelectedIndex =
cboContentRights.SelectedIndex
> End If
> If cboPointOfView.SelectedIndex = -1 Then
> cboPointOfView.SelectedIndex = 1
> Else
> cboPointOfView.SelectedIndex = 1
> End If
> SetEditMode(False)
> End Sub
- Next message: William Ryan eMVP: "Re: Create own Datalayer or Use LLBLGen Pro"
- Previous message: Ryan: "Create own Datalayer or Use LLBLGen Pro"
- In reply to: polynomial5d: "Programmatically determining selected index of combobox produces null error"
- Next in thread: polynomial5d: "RE: Programmatically determining selected index of combobox produces null error"
- Messages sorted by: [ date ] [ thread ]