By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,279 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,279 IT Pros & Developers. It's quick & easy.

How to implement ComboBox.FindValue

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
combobox.SelectedIndex = combobox.FindStringExact(mystring)

"Hal Heinrich" wrote:
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.

Nov 21 '05 #2

P: n/a
Dennis,

You do not understand the question! It is not how use FindStringExact, which
works with the ComboBox.DisplayMember.

The question is how to find the index corresponding to a specific
ComboBox.ValueMember.

Hal

"Dennis" wrote:
combobox.SelectedIndex = combobox.FindStringExact(mystring)

"Hal Heinrich" wrote:
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.

Nov 21 '05 #3

P: n/a
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/de...findtopic1.asp

I hope this helps?

Cor
Nov 21 '05 #4

P: n/a
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/de...findtopic1.asp

I hope this helps?

Cor

Nov 21 '05 #5

P: n/a
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/de...dexoftopic.asp

HTH
rawCoder

"Hal Heinrich" <Ha*********@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.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/de...findtopic1.asp
I hope this helps?

Cor

Nov 21 '05 #6

P: n/a
Thank you!

That is exactly what I was after.

Hal

"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/de...dexoftopic.asp

HTH
rawCoder

"Hal Heinrich" <Ha*********@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.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/de...findtopic1.asp
I hope this helps?

Cor


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.