|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to convert a selectedIndex to SelectedValue for ComboBoxI have a selected index for a combo, which I percieve to be the best value to use when programitically maniplating combos. What I want to be able to do is retrieve the Selected Value for a given Selected Index It may be just me, but I have found the whole selected value, selected text and selectindex to be troublesome to work with. Is there a recommend way to retrive the Selected Value? The way I am currently have to do it it cbo.SelectedIndex = intIndex intValue = cbo.SelectValue But this does not always seem to work and sometimes I find that the selected value is null. Any advice would be appriciated, thanks Mark Hi Mark,
You could use the Item indexer of the ComboBox, but you would then need to cast it to whatever type you put there. For instance, in case of using a DataTable as DataSource, the ComboBox will be full of DataRowViews DataRowView r = (DataRowView)comboBox1.Items[i]; textBox1.Text = r["Col2"].ToString(); On Mon, 16 Jan 2006 17:37:42 +0100, Mark L. Breen <mark.breen@nospam-gmail.com.off> wrote: Show quoteHide quote > Hello All, > > I have a selected index for a combo, which I percieve to be the best value > to use when programitically maniplating combos. > > What I want to be able to do is retrieve the Selected Value for a given > Selected Index > > It may be just me, but I have found the whole selected value, selected text > and selectindex to be troublesome to work with. > > Is there a recommend way to retrive the Selected Value? > > The way I am currently have to do it it > > cbo.SelectedIndex = intIndex > intValue = cbo.SelectValue > > But this does not always seem to work and sometimes I find that the selected > value is null. > > Any advice would be appriciated, thanks > > Mark > > > > -- Happy coding! Morten Wennevik [C# MVP] If no item is selected, or an invalid text combination is entered, no Item
will be selected, thus your SelectedValue will be Nothing/Null. Note: SelectedIndexChanged does not fire when no item is selected even if a previous version was selected. Additionally, if binding the value to a String Property, the value parameter of the Setter will be Nothing/Null even if the property is of the simple String type (not a nullable string). Hence another reason to check your input parameters for all strings. Jim Show quoteHide quote "Mark L. Breen" <mark.breen@nospam-gmail.com.off> wrote in message news:OGyMusrGGHA.3056@TK2MSFTNGP09.phx.gbl... > What I want to be able to do is retrieve the Selected Value for a given > Selected Index > But this does not always seem to work and sometimes I find that the > selected value is null. intValue = cbo.SelectedValue(cbo.SelectedIndex)
Show quoteHide quote "Mark L. Breen" <mark.breen@nospam-gmail.com.off> wrote in message news:OGyMusrGGHA.3056@TK2MSFTNGP09.phx.gbl... > Hello All, > > I have a selected index for a combo, which I percieve to be the best value > to use when programitically maniplating combos. > > What I want to be able to do is retrieve the Selected Value for a given > Selected Index > > It may be just me, but I have found the whole selected value, selected > text and selectindex to be troublesome to work with. > > Is there a recommend way to retrive the Selected Value? > > The way I am currently have to do it it > > cbo.SelectedIndex = intIndex > intValue = cbo.SelectValue > > But this does not always seem to work and sometimes I find that the > selected value is null. > > Any advice would be appriciated, thanks > > Mark > > > Hi Mark,
Nothing to it, if I understand you correctly. (You want to get the value of the currently selected item in your combobox ?) Dim idx as integer = cbo.SelectedIndex if idx <> -1 'If an item is selected Msgbox(cbo.Items(idx).ToString()) End if Regards, Cerebrus. Show quoteHide quote "Mark L. Breen" <mark.breen@nospam-gmail.com.off> wrote in message news:OGyMusrGGHA.3056@TK2MSFTNGP09.phx.gbl... > Hello All, > > I have a selected index for a combo, which I percieve to be the best value > to use when programitically maniplating combos. > > What I want to be able to do is retrieve the Selected Value for a given > Selected Index > > It may be just me, but I have found the whole selected value, selected text > and selectindex to be troublesome to work with. > > Is there a recommend way to retrive the Selected Value? > > The way I am currently have to do it it > > cbo.SelectedIndex = intIndex > intValue = cbo.SelectValue > > But this does not always seem to work and sometimes I find that the selected > value is null. > > Any advice would be appriciated, thanks > > Mark > > >
Display the contents of a folder in a listbox?
How do I extract a page from word and insert into a new word document using VB Image dimensions? ms.public.dotnet.vb.general - an "ex group" Append to XML? Enter key vs Return key Reading dll-Functions and execute them Question on VB.Net security for the application to run on network drive Comm Ports Code for Convert RTF Text to HTML |
|||||||||||||||||||||||