question on ComboBoxes , etc.

H

Henry

Please forgive me if I have missed an obvious answer to this question...

I am looking at controls like comboBoxes, ListBoxes, and Trees and trying to
understand how to associate what is viewed in the controls with the keys
that represent the item values. For example I want to create a dropdown
box in which I display some data from my datasource that represents a
period. The visible text could be anything, but each record is uniquely
defined by an integer value.

When a user selects a value in the drop-down box I want to use the integer
value as input to update a tree control that represents in the database such
as organizations. Each organization also has a unique key and when the user
selects a specified organization I want to use that key to update data in
yet another tree that represents items that belong in that organization.
This could actually go on for a couple more iterations.

When an item in the second tree control is selected I then update a list or
grid control showing properties of the item.

Each key value in his scenario is either a primary key or a foreign in the
underlying tables.

Most of the code samples I have seen show me how to fill in the visible
text, but is there another field or value that I can fill that keeps the key
values? I seem to recall that there is, but I don't know what I am looking
for in the clas properties of these controls.
 
C

Cor Ligthert

Henry

A confusing question,
Most of the code samples I have seen show me how to fill in the visible
text, but is there another field or value that I can fill that keeps the
key values? I seem to recall that there is, but I don't know what I am
looking for in the clas properties of these controls.
Do you ask this for the Combobox or for the treeview what you are talking
about in your text?

Cor
 
H

Henry

I am sorry, I didn't think it was that confusing. It has been a couple of
years since I did any significant programming and then it was in Visual
Basic. I have forgotten a bunch of stuff. Let me try again.

For simplicity sake let us say that my database has four tables.



The first table, Period, represents accounting periods. The table has an id
key field which is an integer and a name field, which is text, varchar(64).
Since the users may put any text they want into the name field, I will not
know ahead of time what is in the name field.



The second table is organization. Organization has the following fields:
id, name, period_id, and parent_id. For any given period, there will be a
unique set or Organizations as identified by period_id. The organization
tree structure has to be built by looking at the parent_id field. There is
one root record per period. The id field is the primary key and is unique.



The third table is Item, representing accounting items, which are also
hierarchical in nature in this scheme. The relevant fields in this table
are: id, name, org_id, and parent_id. For any given organization there are
a set of related items as defined by the org_id field. Like the organization
table, the hierarchic structure must be built from the parent_id field.



The fourth table, properties, represents properties of the items. The
relevant columns are id, item_id, name, and value. For any given Item there
are several related properties.



I want to display the periods as a dropdown box, the organizations as a
tree, the items as a tree, and the properties of items as a list box. In
each case it will be the name fields that are visible to the user, but it is
the id fields that must be used to populate the separate controls. So when
the user chooses period one (1), then I have to build an organization tree
where the organization.period_id is 1. And when the user chooses
organization 1025, I have to fill the item tree with items that have org_id
= 1025. When the user chooses item 5004, I have to fill the list box with
properties that have item_id = 5004.



I am showing text, but my controls have to key off these integers. I am not
sure how to do that.
 
C

Cor Ligthert

Henry,

When you use a dataset with 4 tables, than you can use those tables as a
datasource for your comboboxes.

(I type this very roughly

mycombobox1.DataSource = ds.Tables[0];
mycombobox1.DisplayMember = "Name";
mycombobox1.ValueMember = Id;

The valuemember you can get in the selectedindexchangeevent of the combobox
as
string str = (string) mycombobox1.SelectedValue;

The treeview has not a valuemember, however there is in every treeitem a
tag.
A tag is a place where you can save any object in.

I hope this gives an idea?

Cor
 
C

CometJoe

Henry,
Take a look at the Combobox help for the ValueMember property (and the
DisplayMember property). There is an example showing US State with the
display of the fullname, and the value associated with the
abbreviation.

HTH,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top