?
Solved

How to tie a combo box entries to a value in the same row with Express Quantum Grid?

Posted on 2008-10-07
3
Medium Priority
?
440 Views
Last Modified: 2010-04-21
I am working with Express Quantum Grid 6 and I want to have the following effect:

I have a table that consists of two (for this example) columns, a Type and a SubType.  The Type is a fixed list of items in a combobox and the subtype is a list of items in a combobox BUT it is based on the Type.  For example Type might be a type of car and subtype might be a color so:

Toyota, Red
Toyota, Blue
Toyota, Green
Ford, Blue
Ford, Red

In this example if you drop down the first column and pick Toyota you would get the options of Red, Blue and Green in the 2nd Subtype dropdown.  However if you picked Ford as the type, the Subtype drowndown would only show Blue and Red as options to pick.  This needs to update dynamically on each row so if I pick a row that already had Ford chosen I could only pick Blue and Red even though the last item I worked on might of had Toyota chosen.
0
Comment
Question by:lgallion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 22663117
Use the onInitEdit of the View

it would off course be easier to write a query and use the filled in fields in the where


procedure TForm1.cxGrid1TableView1InitEdit(Sender: TcxCustomGridTableView;
  AItem: TcxCustomGridTableItem; AEdit: TcxCustomEdit);
var aType, aModel, aColor: string;
begin
  aType := '';
  aModel := '';
  aColor := '';
  with Sender.DataController do
    if (RecordCount > 0) and (FocusedRecordIndex >= 0) then
    begin
      aType := VarToStr(Values[FocusedRecordIndex, colType.Index]);
      aModel := VarToStr(Values[FocusedRecordIndex, colModel.Index]);
      aColor := VarToStr(Values[FocusedRecordIndex, colColor.Index]);
    end;
  with TcxCombobox(AEdit).ActiveProperties.Items do
  begin
    if AItem = colType then
    begin
      Add('Toyota');
      Add('VW');
    end;
    if AItem = colModel then
    begin
      // Query for model of type
      if aType = 'Toyota' then
      begin
        Add('Sedan');
        Add('Cabrio');
        Add('Break');
      end else if aType = 'VW' then
      begin
        Add('Break');
        Add('Cabrio');
      end else
        Add('Please select type first');
    end;
    if AItem = colColor then
    begin
      if aType = 'Toyota' then
      begin
        if aModel = 'Sedan' then
        begin
          Add('Red');
          Add('Green');
        end else if aModel = 'Cabrio' then
        begin
          Add('Blue');
          Add('Green');
        end else if aModel = 'Break' then
        begin
          Add('Red');
        end else
          Add('No color for this type and model');
      end else if aType = 'VW' then
      begin
        if aModel = 'Sedan' then
        begin
          Add('Red');
          Add('Green');
        end else if aModel = 'Cabrio' then
        begin
          Add('Blue');
          Add('Green');
        end else if aModel = 'Break' then
        begin
          Add('Red');
        end else
          Add('No color for this type and model');
      end else
        Add('Please select type and model first');
    end;
  end;
end;

Open in new window

0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 2000 total points
ID: 22666722
don't forget to set dcoImmediatePost on the View.DataController.Options
and on the options of the Combobox columns

if you want it from a query


procedure TForm1.AddValues(aType, aModel, aColor: string; aCombo: Integer; List: TStrings);
var Qry: TQuery;
  aField: string;
begin
  List.Clear;
  case aCombo of 
    1: aField := 'CARTYPE';
    2: aField := 'MODEL';
    3: aField := 'COLOR';
  else 
    aField := '';
  end;
  if aField <> '' then 
  begin
    Qry := TQuery.Create(Self);
    try
      Qry.SQL.Text := 
        'SELECT NUMBERPLATE, CARTYPE, MODEL, COLOR FROM CARS '+
        'WHERE (CARTYPE = :CARTYPE or :CARTYPE IS NULL)      '+
        '  AND (MODEL = :MODEL OR :MODEL IS NULL)            '+
        '  AND (COLOR = :COLOR OR :COLOR IS NULL)            ';
      Qry.Prepare;
      Qry.ParamByName('CARTYPE').Value := Null;
      Qry.ParamByName('MODEL').Value := Null;
      Qry.ParamByName('COLOR').Value := Null;
      if aType <> '' then 
        Qry.ParamByName('CARTYPE').AsString := aType;
      if aModel <> '' then 
        Qry.ParamByName('MODEL').AsString := aModel;
      if aColor <> '' then 
        Qry.ParamByName('COLOR').AsString := aColor;
      Qry.Open;
      while Qry.Eof do 
      begin
        if List.IndexOf(Qry.FieldByName(aField).AsString) = -1 then 
          List.Add(Qry.FieldByName(aField).AsString);
        Qry.Next;
      end;
    finally
      Qry.Free;
    end;
  end;
end;
 
procedure TForm1.cxGrid1TableView1InitEdit(Sender: TcxCustomGridTableView;
  AItem: TcxCustomGridTableItem; AEdit: TcxCustomEdit);
var aType, aModel, aColor: string;
  aCombo: integer;
begin
  aType := '';
  aModel := '';
  aColor := '';
  with Sender.DataController do
    if (RecordCount > 0) and (FocusedRecordIndex >= 0) then
    begin
      aType := VarToStr(Values[FocusedRecordIndex, colType.Index]);
      aModel := VarToStr(Values[FocusedRecordIndex, colModel.Index]);
      aColor := VarToStr(Values[FocusedRecordIndex, colColor.Index]);
    end;
  aCombo := 0;
  if aItem = colType then 
    aCombo := 1
  else if aItem = colModel then 
    aCombo := 2
  else if aItem = colColor then 
    aCombo := 3;
  AddValues(aType, aModel, aColor, aCombo, TcxCombobox(AEdit).ActiveProperties.Items);
end;

Open in new window

0
 

Author Closing Comment

by:lgallion
ID: 31503920
Thanks for you quick and complete answer :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question