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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGrid and calculated fields to different cell locations

Status
Not open for further replies.

xxman

Technical User
Jun 1, 2004
80
0
0
US
Hi

I am using Microsoft access, ADO and the data-aware string grid by TMS software. I need to add calculated fields to various cells and on various rows. I am wondering what the proper syntax is for such a request. To clarify. Various calculated fields will be placed in the first row. But in addition up to 3 or 4 rows at a time will be added with various calculated fields. I checked my reference books but as usual nothing is available to show this coding requirement.
 
TMS's event names aren't always what you expect them to be. I'm not sure from your question if you are adding calculated fields to an underlying data set or you want to display the results of a calculation in a specific cell that isn't necessarily related to the row it is on.
 
Hi
I think I`ll change the direction of my question. I want to do a woodworking application that provides a list of all the parts required to build kitchen cabinet drawers. The user will provide data in various editboxes and I`ll do the math on those supplied inputs. Some drawers will require 3 rows and other drawers could fill 4 or more rows with calculated data. Is it better to use bound controls or unbound. The data in the grid could be saved when the user clicked the save button. Not certain what to do. As a added feature the user can choose the notation type at the beginning of the job. Metric, Imperial or Fractional. I wonder what would be easier from a programmers perspective.
 
I would have something dynamic. I've built myself a parameter window that I can add parameters to on the fly to get input from the user. Here is what I have built. It makes use of some DevExpress components but you can use regular components.

I have a form with a TScrollBox called ParamBox. Then, through the procedure below, I add panels inside of the scroll box complete with caption. Depending on the type of parameter I show different components.

I pass three parameters: The caption, the parameter type and something called a finder key which isn't of use to you. I haven't finished how to handle the ftList. I'll probably add another parameter that is a TStringList. One day.

So - with that done I can have my parameters stored in a database, xml, whatever and the user sees a nice looking (IMHO) parameter request form.

Code:
procedure TfrmParameters.AddParameter(const aCaption: string;
  aParamType: TMyParamType; const aFinderKey: integer);
var
  NewPanel: TPanel;
  NewLabel: TLabel;
begin

  if ParamList.IndexOf(UpperCase(aCaption))=-1 then
  begin
    ParamList.Add(Uppercase(aCaption));
  end
  else
    Exit;

  NewPanel := TPanel.Create(ParamBox);
  with NewPanel do
  begin
    Parent := ParamBox;
    Align := alBottom;
    Height := 30;
    Visible := True;

    NewLabel := TLabel.Create(NewPanel);
    NewLabel.Parent := NewPanel;
    NewLabel.Left := 5;
    NewLabel.Top := 7;
    NewLabel.Caption := StrReplaceChar(aCaption,'_',' ');
    NewLabel.Visible := True;
    NewLabel.EllipsisPosition := epEndEllipsis;
    NewLabel.Hint := NewLabel.Caption;
    NewLabel.ShowHint := True;

    case aParamType of
      ftEdit: with TcxTextEdit.Create(NewPanel) do
         begin
           Parent := NewPanel;
           Left := kField_Start_Pos;
           Width := (NewPanel.Width - Left) - 5;
           Anchors := Anchors + [akRight];
           Visible := True;
           Top := 5;
           OnExit := UpdateParamValue;
           Hint := aCaption;
         end;
      ftList: with TcxComboBox.Create(NewPanel) do
         begin
           Parent := NewPanel;
           Left := kField_Start_Pos;
           Width := (NewPanel.Width - Left) - 5;
           Anchors := Anchors + [akRight];
           Visible := True;
           Top := 5;
           with TcxComboBoxProperties(Properties) do
           begin
             Items.Clear;
             items.Add('1');
             items.add('2');
             items.add('3');
           end;
           OnExit := UpdateParamValue;
           Hint := aCaption;
         end;
      ftDate: with TcxDateEdit.Create(NewPanel) do
         begin
           Parent := NewPanel;
           Left := kField_Start_Pos;
           Width := (NewPanel.Width - Left) - 5;
           Anchors := Anchors + [akRight];
           Visible := True;
           Top := 5;
           with TcxDateEditProperties(Properties) do
           begin
             ShowTime := False;
           end;
           OnExit := UpdateParamValue;
           Hint := aCaption;
         end;
      ftCopies: with TcxSpinEdit.Create(NewPanel) do
         begin
           Parent := NewPanel;
           Left := kField_Start_Pos;
           Width := (NewPanel.Width - Left) - 5;
           Anchors := Anchors + [akRight];
           Visible := True;
           Top := 5;
           OnExit := UpdateNumberOfCopies;
           Hint := aCaption;
           with TcxSpinEditProperties(Properties) do
           begin
             MinValue := 1;
             AssignedValues.MinValue := True;
           end;
         end;

    end;
      Align := alTop; //see if it appears under the previous item
  end;

end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top