combo box index question

jvcoach23

Centurion
Joined
May 22, 2003
Messages
192
Location
Saybrook, IL
I have a combo box.. wired up like this

to populate the combo
Code:
                 With Me.cbCounter
                .DisplayMember = "vcCounterName"
                .ValueMember = "intTblPMCounterNameId"
                .DataSource = wsPerfmon.spPMListing_CounterName(intCategory).Tables(0).DefaultView
            End With

on the SelectionChangeCommited1 event.
Code:
 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
Code:
Index and length must refer to a location within the string
can someone tell me what I'm doing wrong.
thanks
 
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)
 
Robby said:
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
 
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
 
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


jvcoach23 said:
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
 
Back
Top