Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a combo box.. wired up like this

 

to populate the combo

                With Me.cbCounter
               .DisplayMember = "vcCounterName"
               .ValueMember = "intTblPMCounterNameId"
               .DataSource = wsPerfmon.spPMListing_CounterName(intCategory).Tables(0).DefaultView
           End With

 

on the SelectionChangeCommited1 event.

intCounter = Me.cbCounter.SelectedValue
           vcCounter = Me.cbCounter.SelectedText

 

the data coming to that query

looks like this

intTblPMCounterNameId vcCounterName

1 % Processor Time

4 % User Time

 

when I select % Processor Time, the selected value is 1 and the selected text is % User Time. When I select % User Time, intCounter is set to 4, that makes sense.. but the selectedtext gives me an error

Index and length must refer to a location within the string

can someone tell me what I'm doing wrong.

thanks

JvCoach23

VB.Net newbie

MS Sql Vet

  • Moderators
Posted

There are three items you can/should query here...

 

dd.SelectedItem.Text (the actual text displayed in the UI..."Processor Time" or "User Time")

dd.SelectedItem.Value (the underlying value...1 or 4)

dd.SelectedIndex (The index of the collection starting with the number zero...0 or 1)

Visit...Bassic Software
Posted
There are three items you can/should query here...

 

dd.SelectedItem.Text (the actual text displayed in the UI..."Processor Time" or "User Time")

dd.SelectedItem.Value (the underlying value...1 or 4)

dd.SelectedIndex (The index of the collection starting with the number zero...0 or 1)

 

need some more clarification. I see what you are saying.. but would like to understand why. The error happens when I try to get the value of the selectedText. If I try to get the value of the selectd index, how does that help the selected text not to produce an error.

 

hope your willing to explain.. like to learn why.

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

strange happenings

 

I have been working with this combo box some more. The first time I run through my code.. the selectedindex is = 1 when I choose % User Time. The selectedvalue = 4, the selected text gives me the error. So I wrapped it in a try and catch, so that I could have it go through it again without stopping the code.. the second time through, i choose the % User Time, the selectedindex again was 1, the selected value =4 and this time the selectedtext came back correctly... % User Time. can someone help me understand what I'm doing wrong.

 

Again, when I choose % Processor time (index of 0, value of 1) and choose that the first time through it works.. just happens when I select % User Time. Those are the only two value I have in the dataset.

 

hope someone can help

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

I find it easiest just to retrieve the underlying DataRow so that I have access to all of the Data:

(I apologize if I screw up the VB....I mainly use C# :-\ )

 

Dim rowSelected as DataRowView

 

rowSelected = CType(Me.cbCounter.SelectedItem, DataRowView)

 

intCounter = rowSelected("intTblPMCounterNameId")

vcCounter = rowSelected("vcCounterName")

 

' You now have access to all the Data in the bound DataRow

 

 

I have been working with this combo box some more. The first time I run through my code.. the selectedindex is = 1 when I choose % User Time. The selectedvalue = 4, the selected text gives me the error. So I wrapped it in a try and catch, so that I could have it go through it again without stopping the code.. the second time through, i choose the % User Time, the selectedindex again was 1, the selected value =4 and this time the selectedtext came back correctly... % User Time. can someone help me understand what I'm doing wrong.

 

Again, when I choose % Processor time (index of 0, value of 1) and choose that the first time through it works.. just happens when I select % User Time. Those are the only two value I have in the dataset.

 

hope someone can help

thanks

shannon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...