Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How come this works, but this doesnt (TListview & TTeeChart)

Status
Not open for further replies.

simmo09

Programmer
Apr 22, 2009
82
GB
Hi, i was populating a teechart based on if a certain subitem contained a value (got some help from here).

the code was this (which works):

Code:
procedure TfrmMain.UpdateWeightSeries;
var
  i: Integer;
  aStringList: TStringList;
begin
  aStringList:= TStringList.Create;

  try
    with WeightSeries do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the fitness table and:
      -> get the value entered in all weight subitem boxes
      -> add to the fitness chart the number of weeks based on if weight has a value}
      for i:= 0 to lvwFitnessTable.Items.Count -1 do
      begin
        if lvwFitnessTable.Items[i].SubItems.Count > 7 then
        begin
          if lvwFitnessTable.Items[i].SubItems[7] <> '' then
          begin
            {add weight values to stringlist}
            aStringList.Add(lvwFitnessTable.Items[i].SubItems[7]);

            {add to the chart, we can now count actual weeks via aStringList.Count}
            Add(StrToFloat(lvwFitnessTable.Items[i].SubItems[7]), IntToStr(aStringList.Count), clMedGray);
          end;
        end;
      end;
    end;
  finally
    aStringList.Free;
  end;
end;


now what i would like is, i have a new column in the listview, if the string in this subitem (11) says 'Yes' then i want the chart to update, if it says 'No' i dont want it to do anything. This new column is basically a easier way for the user to choose if they want the SubItem[7] to be shown on the chart or not, i cant seem to get it to work. here is what i have so far and hope someone can help me:



Code:
procedure TfrmMain.UpdateWeightSeries;
var
  i: Integer;
  aStringList: TStringList;
begin
  aStringList:= TStringList.Create;

  try
    with WeightSeries do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the fitness table and:
      -> get the value entered in all subitem weight boxes
      -> add to the fitness chart the number of weeks based on if weight has a value, and subitem[11] says 'Yes'}

      for i:= 0 to lvwFitnessTable.Items.Count -1 do
      begin
        if lvwFitnessTable.Items[i].SubItems.Count > 7 then
        begin
          if lvwFitnessTable.Items[i].SubItems[7] <> '' then
          begin
            [b]if lvwFitnessTable.Items[i].SubItems[11] = 'Yes' then {did user request to monitor this entry?}
            begin
              {add weight values to stringlist}
              aStringList.Add(lvwFitnessTable.Items[i].SubItems[7]);

              {add to the chart, we can now count actual weeks via aStringList.Count}
              Add(StrToFloat(lvwFitnessTable.Items[i].SubItems[7]), IntToStr(aStringList.Count), clMedGray);
            end;[/b]
          end;
        end;
      end;
    end;
  finally
    aStringList.Free;
  end;
end;



Please help me, thanks!!
 
User options are typical. The options typically grow over time. Therefore it would not be my recomendation to add columns to a ListView to display user options. What if you got up to or over 10? I'd start by putting them where they belong, like in a menu or toolbar, but not in the data...

Roo
Delphi Rules!
 
hi again roo, i can see your point of view, however i dont actually have that many columns (well i do, but they are small so including this isnt much of a problem for me).

anyway this way would work ok for my purposes, i just need to know to get it to work.

so if you could help me with that i would be very grateful.

Thanks ;)
 
i worked out a more logical approach to it, without using extra columns like you suggested.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top