jvcoach23 Posted December 9, 2004 Posted December 9, 2004 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
Moderators Robby Posted December 9, 2004 Moderators Posted December 9, 2004 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) Quote Visit...Bassic Software
jvcoach23 Posted December 10, 2004 Author Posted December 10, 2004 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
jvcoach23 Posted December 13, 2004 Author Posted December 13, 2004 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
RobEmDee Posted December 14, 2004 Posted December 14, 2004 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 Quote
jvcoach23 Posted December 14, 2004 Author Posted December 14, 2004 good deal, i'll give it a shot Quote JvCoach23 VB.Net newbie MS Sql Vet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.