Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
changing items in combobox Posted by bcTune33 on 28 Jun 2005 at 5:58 PM
Hey everyone,

I am trying to write a program for sports card collectors which will manage an access database. I am having trouble with my "Teams" combobox.

Here is basically what is supposed to happen:
I have a RadioGroup set up which contains the following choices:
Baseball, Basketball, Football, Hockey, Other
When you choose one of these, basketball for instance, a list of the NBA teams will be loaded into the Teams ComboBox.
When you get to the next record, if you would change it over to Baseball, the MLB teams will be loaded into the ComboBox.

My question is, is there a way to save off an array of these team names and then also is there a way to add the array to the ComboBox?
I've tried several methods but I have yet to find one that works.

Thanks in advance.
*----------------------------------------*

There are two ways to write error-free programs; only the third one works.


Report
Re: changing items in combobox Posted by leopangaribuan on 29 Jun 2005 at 12:29 AM
: Hey everyone,
:
: I am trying to write a program for sports card collectors which will manage an access database. I am having trouble with my "Teams" combobox.
:
: Here is basically what is supposed to happen:
: I have a RadioGroup set up which contains the following choices:
: Baseball, Basketball, Football, Hockey, Other
: When you choose one of these, basketball for instance, a list of the NBA teams will be loaded into the Teams ComboBox.
: When you get to the next record, if you would change it over to Baseball, the MLB teams will be loaded into the ComboBox.
:
: My question is, is there a way to save off an array of these team names and then also is there a way to add the array to the ComboBox?
: I've tried several methods but I have yet to find one that works.
:
: Thanks in advance.
: *----------------------------------------*
:
: There are two ways to write error-free programs; only the third one works.
:
:
:
hi there,
you're working with a database,right?well,basically in the radiogroup onclick event you can query the selected teams based on the selected league in the radiogroup then you can use the query results and load them to the combobox using:
combobox1.clear;//clear the box so it wont create duplicate items!
adoquery1.first;
while(not adoquery1.eof)do
begin
combobox1.items.add(adoquery1.fieldbyname('fieldname').asstring);
adoquery1.next
end;
Report
Re: changing items in combobox Posted by bcTune33 on 29 Jun 2005 at 1:48 PM
Hello,

Yes, i am working with a database, however that is not quite what I need. I don't need to perform a query for the combobox items. Basically what the program is doing is maintaining a database which will sort a baseball/football, etc card collection. The database contains items such as LastName, FirstName, CardNumber, CardYear, Value, etc.

What I am trying to do is to have team lists saved off in a TStringList or something to that effect, and then just set the combobox's items to that list depending up on which radio button was selected. However I have yet to find a way to change the combobox's items.

Let me know if you have any ideas or need more info.

Thanks alot.
*----------------------------------------*

There are two ways to write error-free programs; only the third one works.



Report
Re: changing items in combobox Posted by zibadian on 29 Jun 2005 at 2:54 PM
: Hello,
:
: Yes, i am working with a database, however that is not quite what I need. I don't need to perform a query for the combobox items. Basically what the program is doing is maintaining a database which will sort a baseball/football, etc card collection. The database contains items such as LastName, FirstName, CardNumber, CardYear, Value, etc.
:
: What I am trying to do is to have team lists saved off in a TStringList or something to that effect, and then just set the combobox's items to that list depending up on which radio button was selected. However I have yet to find a way to change the combobox's items.
:
: Let me know if you have any ideas or need more info.
:
: Thanks alot.
: *----------------------------------------*
:
: There are two ways to write error-free programs; only the third one works.
:
:
:
:
The Items of a combobox are stored in a TStrings object, which is also an ancestor of the TStringList object. So to copy the values from a TStringList into the Items, the only code you need is this:
  ComboBox1.Items := SomeStringList;

Alternatively, you can also use this, which shows what's happening:
  ComboBox.Items.Clear;
  for i := 0 to SomeStringList.Count-1 do
    ComboBox.Items.Add(SomeStringList[i]);

This code can also be used to copy part of the SomeStringList into the ComboBox.
Report
Re: changing items in combobox Posted by bcTune33 on 29 Jun 2005 at 3:33 PM
This message was edited by bcTune33 at 2005-6-29 15:51:13

Thanks. That sounds better than what I was trying to do...but now I'm getting the following error:

Variable 'baseballTeamsList' Might not have been initialized.

Here is my code thus far. I'm only adding one team at this point and i can't get past that error.

procedure TForm3.RadioGroup1Click(Sender: TObject);
var
selectedInt:integer;
baseballTeamsList:TstringList;

begin
selectedInt:=RadioGroup1.ItemIndex; //0 for baseball, 4 for other
baseballTeamsList.Add('Angels');
if (selectedInt=0) then //Baseball
TeamCB.Clear;
TeamCB.Items:=baseballTeamsList;
*----------------------------------------*

There are two ways to write error-free programs; only the third one works.





Report
Re: changing items in combobox Posted by zibadian on 29 Jun 2005 at 9:31 PM
: This message was edited by bcTune33 at 2005-6-29 15:51:13

: Thanks. That sounds better than what I was trying to do...but now I'm getting the following error:
:
: Variable 'baseballTeamsList' Might not have been initialized.
:
: Here is my code thus far. I'm only adding one team at this point and i can't get past that error.
:
: procedure TForm3.RadioGroup1Click(Sender: TObject);
: var
: selectedInt:integer;
: baseballTeamsList:TstringList;
:
: begin
: selectedInt:=RadioGroup1.ItemIndex; //0 for baseball, 4 for other
: baseballTeamsList.Add('Angels');
: if (selectedInt=0) then //Baseball
: TeamCB.Clear;
: TeamCB.Items:=baseballTeamsList;
: *----------------------------------------*
:
: There are two ways to write error-free programs; only the third one works.
:
:
You haven't created the baseballTeamsList in your code, which means that that object doesn't exists in the memory yet. If you run this code it will stop at the red line with and "Access Violation"-exception.
To solve this, first create the object using its constructor.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.