Home All Groups Group Topic Archive Search About

Combobox, ITEMData and Reselected previous item

Author
9 May 2005 6:49 PM
Adal
Hi,
I'm working on vb6 with sql server 2000 and I have little problem. I'm using
a combobox to allow the user select an account number and a department number
whe filling out the form.
Currently, when I load the form, I retrieve the information from two tables
on sql server. Each table has 1 ID column and 1 Description column. Both ID
columns are numeric. The description column is added to the combobox with
additem method. I load the ID as a new index. The code that does this job is
the next one:

Do While rs.EOF = False
            .CmbDept.AddItem Trim(rs.Fields("dept_des"))
            .CmbDept.ItemData(.CmbDept.NewIndex) = Trim(rs.Fields("dept_num"))
            rs.MoveNext
Loop

The problem I have, is how to reselect the combobox item that was saved by
the user once he wants to modify it. As I see it, I have two options:

1. During the loop compare each ID with the ID that was previously stored
and save to a variable the index. The way to knoe the index is trhough a
separate counter.
2. After the combobox is filled, search the ID in the combobox.

The reason I need to reselected the ITEM, it's because the user can modify
the information he has captured before. Since I'm using the same form for new
entries and for the modification of existing entries, I have to reselect the
saved item when the user does a modification. So I'm guessing option 1 is not
as good, because it will be done each time, and option 2 can be done only
when the form is loaded for modification of the entry.

Is there a better way to give the user a list of items for him to chose from?

The other thing that can be done is to use a disconnected recordset with the
information from the table, and use the rsfind method to reselected the item,
but I do not want to do this, since I already have one disconnected recordset
with a lot of information, use to simulate an autocomplete textbox.

Thanks for any help.

Author
9 May 2005 7:13 PM
Saga
Just a remark on your code, you don't need the trim()
function in the statement where you assign the itemdata.

Saga

Show quoteHide quote
"Adal" <A***@discussions.microsoft.com> wrote in message
news:90958A4F-8220-441A-972F-0D27BF8AE250@microsoft.com...
> Hi,
> I'm working on vb6 with sql server 2000 and I have little problem. I'm
> using
> a combobox to allow the user select an account number and a department
> number
> whe filling out the form.
> Currently, when I load the form, I retrieve the information from two
> tables
> on sql server. Each table has 1 ID column and 1 Description column.
> Both ID
> columns are numeric. The description column is added to the combobox
> with
> additem method. I load the ID as a new index. The code that does this
> job is
> the next one:
>
> Do While rs.EOF = False
>            .CmbDept.AddItem Trim(rs.Fields("dept_des"))
>            .CmbDept.ItemData(.CmbDept.NewIndex) =
> Trim(rs.Fields("dept_num"))
>            rs.MoveNext
> Loop
>
> The problem I have, is how to reselect the combobox item that was
> saved by
> the user once he wants to modify it. As I see it, I have two options:
>
> 1. During the loop compare each ID with the ID that was previously
> stored
> and save to a variable the index. The way to knoe the index is trhough
> a
> separate counter.
> 2. After the combobox is filled, search the ID in the combobox.
>
> The reason I need to reselected the ITEM, it's because the user can
> modify
> the information he has captured before. Since I'm using the same form
> for new
> entries and for the modification of existing entries, I have to
> reselect the
> saved item when the user does a modification. So I'm guessing option 1
> is not
> as good, because it will be done each time, and option 2 can be done
> only
> when the form is loaded for modification of the entry.
>
> Is there a better way to give the user a list of items for him to
> chose from?
>
> The other thing that can be done is to use a disconnected recordset
> with the
> information from the table, and use the rsfind method to reselected
> the item,
> but I do not want to do this, since I already have one disconnected
> recordset
> with a lot of information, use to simulate an autocomplete textbox.
>
> Thanks for any help.
Author
9 May 2005 9:26 PM
Larry Serflaten
"Adal" <A***@discussions.microsoft.com> wrote

> The problem I have, is how to reselect the combobox item that was saved by
> the user once he wants to modify it. As I see it, I have two options:
>
> The reason I need to reselected the ITEM, it's because the user can modify
> the information he has captured before. Since I'm using the same form for new
> entries and for the modification of existing entries, I have to reselect the
> saved item when the user does a modification.

When does it get unselected?

LFS
Author
9 May 2005 11:48 PM
Adal
It gets deselected when the user saves the entrie and then closes it, so when
he wants to modify it again (lets say, in the next day) the data needs to get
reloaded, so I have to select the department the user saved and the account
number.
Author
10 May 2005 3:24 PM
Saga
Ok, let me see if I understand this. The user comes in and selects
the department. This is turn causes the department's data to load.
The user then modifies the data and saves it. S/He then closes the
dialog and comes back later and this is when the item is unselected?

This is usually normal operation. The user, everytime s/he comes
to that dialog will have to select the departemnt again. Now if you
want the application to remember the last department that was selected,
then you need to add some code to save the user's selection somewhere,
such as a db, INI file or registry.

Once the dept. is selected, the click event fires. Here in addition to
what
you have, you add the code to save the ItemData(). Then, in the form
load
event, you add code to read the last selection, search for it in the
list's
ItemData array and select the item when found.

If you use the registry, you can have a look at the getsetting and
savesetting
procedures.

Good luck!
Saga


Show quoteHide quote
"Adal" <A***@discussions.microsoft.com> wrote in message
news:B4132529-4CC1-4104-BE77-A211BDEFCA3D@microsoft.com...
> It gets deselected when the user saves the entrie and then closes it,
> so when
> he wants to modify it again (lets say, in the next day) the data needs
> to get
> reloaded, so I have to select the department the user saved and the
> account
> number.
Author
10 May 2005 7:00 PM
Adal
thanks for the answer. To sum up, the obvious has to be done and there is no
other way to do it: after I load the combo, I have to search the entire combo
for the ITEM data that matches the value I have saved on the DB. Well, I
though there was another way to do it, like a disconnected stored procedure
instead of a combo or something else. Maybe using the combo box bound to an
ado control (but I do not like this one).

thanks