473,396 Members | 1,608 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,396 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 1411
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.