changing items in combobox - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

changing items in combobox

bcTune33bcTune33 Posts: 12Member
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.


Comments

  • leopangaribuanleopangaribuan Posts: 5Member
    : 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;
  • bcTune33bcTune33 Posts: 12Member
    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.



  • zibadianzibadian Posts: 6,349Member
    : 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:
    [code]
    ComboBox1.Items := SomeStringList;
    [/code]
    Alternatively, you can also use this, which shows what's happening:
    [code]
    ComboBox.Items.Clear;
    for i := 0 to SomeStringList.Count-1 do
    ComboBox.Items.Add(SomeStringList[i]);
    [/code]
    This code can also be used to copy part of the SomeStringList into the ComboBox.
  • bcTune33bcTune33 Posts: 12Member
    [b][red]This message was edited by bcTune33 at 2005-6-29 15:51:13[/red][/b][hr]
    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.





  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by bcTune33 at 2005-6-29 15:51:13[/red][/b][hr]
    : 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
    :[red] baseballTeamsList.Add('Angels');[/red]
    : 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.
Sign In or Register to comment.