Re: Having trouble understanding assignement of Object in this instance

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




RSH wrote:
> I am slowly getting the hang of objects and creating my own. I was given
> some help in assigning an object to a ComboBox collection. I have been
> looking at it and I get the concept which is very powerful but I'm having a
> bit of a problem conceptually. I was hoping someone might be able to shed
> some light on creating this object and assigning it in the manner. Also how
> would I reference this object by name after it is created in this manner?
> Is there a collection of objects that I could iterate through with respect
> to this ComboBox?
[snip code]

Objects don't necessarily have names, and collections don't necessarily
support getting contained members by name. Of course, there's always
_some_ way to 'get at' them. You can see that here in the case of these
Employee objects that you put in the ComboBox. See the line where you
put them in:

ComboList.Items.Add(new Employee(sTemp, DR));

that tells you that ComboBox ComboList has a a collection object called
Items. So you go to the documentation (or just the object browser) and
you see

>>
[C#]
public ComboBox.ObjectCollection Items {get;}

A System.Windows.Forms.ComboBox.ObjectCollection representing the items
in the ComboBox.

Remarks
This property enables you to obtain a reference to the list of items
that are currently stored in the ComboBox. With this reference, you can
add items, remove items, and obtain a count of the items in the
collection. For more information on the tasks that can be performed
with the item collection, see the
System.Windows.Forms.ComboBox.ObjectCollection class reference topics.
>>

So then you go and look at ComboBox.ObjectCollection, to see the ways
you can get objects back out of the collection. And you see that this
class implements IEnumerable, which means you can foreach over the
collection. So that's one way you can get each item back. Another way
is the indexer for the collection - Items[0] is the first member of the
collection, Items[1] is the second, and so on.

--
Larry Lard
Replies to group please

.



Relevant Pages

  • Re: And a question on objects
    ... but my question is: do I need to free Ptr every time ... pointers to objects are stored in the items of a combobox. ... one pointer to every object is ... reference away, the object should then have been Freed. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Having trouble understanding assignement of Object in this instance
    ... >> some help in assigning an object to a ComboBox collection. ... >> some light on creating this object and assigning it in the manner. ... >> would I reference this object by name after it is created in this manner? ... > System.Windows.Forms.ComboBox.ObjectCollection class reference topics. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reporting Out Two Names w/Phone # from the Same Table
    ... The combobox on the form where the data's entered already pulls in multiple ... then you can pull it from the combobox. ... Reference the column in the combobox like this: ... ServiceReport table, and contacts are stored in a separate table, which feeds ...
    (microsoft.public.access.reports)
  • Re: Form to query
    ... reference to the form and I have disactivated the combobox for Causali ... If I run the query any other way I get a blank form.... ...
    (microsoft.public.access.forms)
  • Excel ActiveX Combo - AutoComplete and LIst Issues
    ... blank rows otherwise they will be displayed in the combobox. ... defined the offset function as a name so I can easily reference it. ... Load the data into an array and then set the list from the array. ...
    (microsoft.public.excel.programming)