473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Searching control of objects

I'm looking for an easy way to find the value member of an object in a
control. I have an ArrayList of a simple class with two properties. One
property is "Id" and the other is "CompName" (both stings). On my form I
have a CheckListBox and I bind the ArrayList of Company's like so.

Clb.DisplayMember = "CompName"

Clb.ValueMember = "Id"

Clb.DataSource = alCompany

I have a second ArrayList with stings that match the Id of some of the
companies that I want to set the check state. But with the folling code I
always get a -1 index. Is there another way except looping through the
entire CheckListBox for every Id in the Second ArrayList? The Obj.ToString
is holding a valid Id, but its not finding it.

Dim obj as Object

Dim intLoop as Integer

For each obj in alCheckTheseId

intLoop = clb.ValueMemeber.IndexOf(Obj.ToString)

if intLoop > -1 Then

clb.SetItemChecked(intLoop, True)

end if

Next

MANY THX,

-Randy
Jul 21 '05 #1
2 1408
When you step through the code, what value is obj.ToString giving you? It's
probably going to be something like this:
System.Windows.Forms.Button, Text: Button1
You may want to cast the object to a specific type and interrogate a
specific property
Also, it looks like you are trying to get the ValueMember which if I'm
reading this correctly is always going to be ID for that specific listbox.
So that code is going to find the Index of the Literal "ID" which will be
the same for each item in the listbox...ValueMember doesn't change for each
itme.

What ultimately are you trying to do with the two arraylists? If you are
trying to match items and values, there's definitely more straightforward
approaches. Moreoever, you may want to make a class and use reflection to
grab the properties depending on what the ultimate goal is.

HTH,

Bill

intLoop = clb.ValueMemeber.IndexOf(Obj.ToString)


"Randy" <ra***@penHATESPAMsoft.com> wrote in message
news:#M**************@TK2MSFTNGP11.phx.gbl...
I'm looking for an easy way to find the value member of an object in a
control. I have an ArrayList of a simple class with two properties. One
property is "Id" and the other is "CompName" (both stings). On my form I
have a CheckListBox and I bind the ArrayList of Company's like so.

Clb.DisplayMember = "CompName"

Clb.ValueMember = "Id"

Clb.DataSource = alCompany

I have a second ArrayList with stings that match the Id of some of the
companies that I want to set the check state. But with the folling code I
always get a -1 index. Is there another way except looping through the
entire CheckListBox for every Id in the Second ArrayList? The Obj.ToString is holding a valid Id, but its not finding it.

Dim obj as Object

Dim intLoop as Integer

For each obj in alCheckTheseId

intLoop = clb.ValueMemeber.IndexOf(Obj.ToString)

if intLoop > -1 Then

clb.SetItemChecked(intLoop, True)

end if

Next

MANY THX,

-Randy

Jul 21 '05 #2
obj.ToString value is something like "1085" {string}. The ultimate goal is
to fill the CheckListBox with all possible companies and allow the user to
save any checked companies to later load. The first ArrayList holds all the
Company objects and the second comes from the database and holds just the
Id's of the companies that were checked. I thought ValueMember was a
companion to DisplayMember when objects are added to a control. The same as
VB6 when you have...

' User sees Comany A in combobox, but has a value of 23
Combo1.AddItem "Company A"
Combo1.ItemData(combo1.NewIndex) = 23

In my first example, alCheckTheseId is the second ArrayList of strings. It
holds the Id if the checked companies. Simply I need to match the value of
a property in a list of objects.

-Randy
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ef**************@TK2MSFTNGP10.phx.gbl...
When you step through the code, what value is obj.ToString giving you? It's probably going to be something like this:
System.Windows.Forms.Button, Text: Button1
You may want to cast the object to a specific type and interrogate a
specific property
Also, it looks like you are trying to get the ValueMember which if I'm
reading this correctly is always going to be ID for that specific listbox.
So that code is going to find the Index of the Literal "ID" which will be
the same for each item in the listbox...ValueMember doesn't change for each itme.

What ultimately are you trying to do with the two arraylists? If you are
trying to match items and values, there's definitely more straightforward
approaches. Moreoever, you may want to make a class and use reflection to
grab the properties depending on what the ultimate goal is.

HTH,

Bill

intLoop = clb.ValueMemeber.IndexOf(Obj.ToString)


"Randy" <ra***@penHATESPAMsoft.com> wrote in message
news:#M**************@TK2MSFTNGP11.phx.gbl...
I'm looking for an easy way to find the value member of an object in a
control. I have an ArrayList of a simple class with two properties. One property is "Id" and the other is "CompName" (both stings). On my form I have a CheckListBox and I bind the ArrayList of Company's like so.

Clb.DisplayMember = "CompName"

Clb.ValueMember = "Id"

Clb.DataSource = alCompany

I have a second ArrayList with stings that match the Id of some of the
companies that I want to set the check state. But with the folling code I always get a -1 index. Is there another way except looping through the
entire CheckListBox for every Id in the Second ArrayList? The

Obj.ToString
is holding a valid Id, but its not finding it.

Dim obj as Object

Dim intLoop as Integer

For each obj in alCheckTheseId

intLoop = clb.ValueMemeber.IndexOf(Obj.ToString)

if intLoop > -1 Then

clb.SetItemChecked(intLoop, True)

end if

Next

MANY THX,

-Randy


Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
14
by: Ludwig77 | last post by:
I read that there are some tags that can be entered in a web page's meta tags in order to prevent web bot searching and indexing of the web page for search engines. What is the tagging that I...
8
by: YunusEmre | last post by:
Hi, I have a class named MyDataAdapter that derives from System.ComponentModel.Component and it contains all of my SqlDataAdapter objects(around a 100). How can I find a SqlDataAdapter in the...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
2
by: Randy | last post by:
I'm looking for an easy way to find the value member of an object in a control. I have an ArrayList of a simple class with two properties. One property is "Id" and the other is "CompName" (both...
6
by: AAJ | last post by:
Hi all I have some objects that I add to an ArrayList. Each object is from the same class and has methods etc. Each can be identified by a unique property, in this case PK e.g. PK =1 for...
4
by: Jordan S. | last post by:
Using .NET 2.0 (C#) I'm writing a small app that will have a "Person" class that exposes FirstName and LastName properties. At runtime, a "People" collection will be populated with a few thousand...
3
by: wbarker45 | last post by:
I'm really having a tough time getiing the Tab Control to accept the various objects and controls (List Boxes, and others). In Form design mode, after creating a 2 page Tab Control, I have dragged...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.