Home All Groups Group Topic Archive Search About

How to implement ComboBox.FindValue

Author
25 Mar 2005 1:09 AM
Hal Heinrich
How do I implement the value equivalent of the ComboBox.FindStringExact
method?

I.e. How do I set the ComboBox.SelectedIndex so that the
ComboBox.SelectedValue object matches one that I specify.

Thanks in advance for any help,
Hal Heinrich
VP Technology
Aralan Solutions Inc.

Author
25 Mar 2005 7:42 AM
Cor Ligthert
Hal,

When I had not read your answer to Dennis I would have given the same answer
as he.

Therefore it is true that probably Dennis did not understand your question,
probably because of the way the question was asked.

The answer is simple, use a dataview (or defaultview) as datasource and use
a dataview.find to find the rowindex. That you can set to your
selectedindex.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadataviewclassfindtopic1.asp

I hope this helps?

Cor
Author
30 Mar 2005 10:09 PM
Hal Heinrich
Cor,

Thanks for your reply. I'd like to rephrase the question as follows:

Can you provide an implementation for the following function definition?

    Public Function FindValue(ByVal cb As System.Windows.Forms.ComboBox,
ByVal obj As Object) As Integer
        'Parameters
        '   cb
        '      the ComboBox to be searched
        '   obj
        '      the Object to search for
        '
        'Return Value
        '   The zero-based index of the first item found; returns -1 if no
match is found.
        '
        'Remarks
        '   Uses the Equals method of the Object class to determine a match
        '   returns the index for which the following is true:
        '   obj.Equals(cb.SelectedItem)
        '
    End Function

Thanks,
Hal

Show quoteHide quote
"Cor Ligthert" wrote:

> Hal,
>
> When I had not read your answer to Dennis I would have given the same answer
> as he.
>
> Therefore it is true that probably Dennis did not understand your question,
> probably because of the way the question was asked.
>
> The answer is simple, use a dataview (or defaultview) as datasource and use
> a dataview.find to find the rowindex. That you can set to your
> selectedindex.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadataviewclassfindtopic1.asp
>
> I hope this helps?
>
> Cor
>
>
>
Author
30 Mar 2005 10:19 PM
rawCoder
if cb.items.contains(obj) then
    return cb.items.indexOf( obj)
else
    return -1
end if

Does this work for you ?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscomboboxobjectcollectionclassindexoftopic.asp

HTH
rawCoder

Show quoteHide quote
"Hal Heinrich" <HalHeinr***@discussions.microsoft.com> wrote in message
news:8A320415-75B8-4214-80ED-E4EC78464C4E@microsoft.com...
> Cor,
>
> Thanks for your reply. I'd like to rephrase the question as follows:
>
> Can you provide an implementation for the following function definition?
>
>     Public Function FindValue(ByVal cb As System.Windows.Forms.ComboBox,
> ByVal obj As Object) As Integer
>         'Parameters
>         '   cb
>         '      the ComboBox to be searched
>         '   obj
>         '      the Object to search for
>         '
>         'Return Value
>         '   The zero-based index of the first item found; returns -1 if no
> match is found.
>         '
>         'Remarks
>         '   Uses the Equals method of the Object class to determine a
match
>         '   returns the index for which the following is true:
>         '   obj.Equals(cb.SelectedItem)
>         '
>     End Function
>
> Thanks,
> Hal
>
> "Cor Ligthert" wrote:
>
> > Hal,
> >
> > When I had not read your answer to Dennis I would have given the same
answer
> > as he.
> >
> > Therefore it is true that probably Dennis did not understand your
question,
> > probably because of the way the question was asked.
> >
> > The answer is simple, use a dataview (or defaultview) as datasource and
use
> > a dataview.find to find the rowindex. That you can set to your
> > selectedindex.
> >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadataviewclassfindtopic1.asp
Show quoteHide quote
> >
> > I hope this helps?
> >
> > Cor
> >
> >
> >
Author
31 Mar 2005 4:07 PM
Hal Heinrich
Thank you!

That is exactly what I was after.

Hal

Show quoteHide quote
"rawCoder" wrote:

> if cb.items.contains(obj) then
>     return cb.items.indexOf( obj)
> else
>     return -1
> end if
>
> Does this work for you ?
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscomboboxobjectcollectionclassindexoftopic.asp
>
> HTH
> rawCoder
>
> "Hal Heinrich" <HalHeinr***@discussions.microsoft.com> wrote in message
> news:8A320415-75B8-4214-80ED-E4EC78464C4E@microsoft.com...
> > Cor,
> >
> > Thanks for your reply. I'd like to rephrase the question as follows:
> >
> > Can you provide an implementation for the following function definition?
> >
> >     Public Function FindValue(ByVal cb As System.Windows.Forms.ComboBox,
> > ByVal obj As Object) As Integer
> >         'Parameters
> >         '   cb
> >         '      the ComboBox to be searched
> >         '   obj
> >         '      the Object to search for
> >         '
> >         'Return Value
> >         '   The zero-based index of the first item found; returns -1 if no
> > match is found.
> >         '
> >         'Remarks
> >         '   Uses the Equals method of the Object class to determine a
> match
> >         '   returns the index for which the following is true:
> >         '   obj.Equals(cb.SelectedItem)
> >         '
> >     End Function
> >
> > Thanks,
> > Hal
> >
> > "Cor Ligthert" wrote:
> >
> > > Hal,
> > >
> > > When I had not read your answer to Dennis I would have given the same
> answer
> > > as he.
> > >
> > > Therefore it is true that probably Dennis did not understand your
> question,
> > > probably because of the way the question was asked.
> > >
> > > The answer is simple, use a dataview (or defaultview) as datasource and
> use
> > > a dataview.find to find the rowindex. That you can set to your
> > > selectedindex.
> > >
> > >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadataviewclassfindtopic1.asp
> > >
> > > I hope this helps?
> > >
> > > Cor
> > >
> > >
> > >
>
>
>