Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1806
  • Last Modified:

Regarding Express Grid Control - Combobox inside Express Quantum Grid detail record

Hi Folks ,

I have grid with a master - detail relationship  (Used Express VCL Quantum Grid ) the master table will have the record and the corresponding detail will be displayed below during master record expand detail will be shown and detail record has four columns and i am making it one of the column to be combo box by changing the custom edit properties.Now i want to populate the values inside the combo box based on the value of one of the master record column.My question is in which event i need to write the code to add data in the combo box.I am trying to write in the detail focussed record changed event is that right ?? I have provided the sample code below .Please advise me on this

Thanks in advance.
 
procedure TForm2.cxGrid1DBTableView2FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
const 
C_Query_New = 'select NewMethod from "C:\RAPID\RPFILES\PrintLocation.db4" where PrintLocationName = ''%0:s''';
var PrintLocation : String;
begin
try
(TcxComboBoxProperties(cxGrid1DBTableView2NEWMETHOD.Properties)).Items.Clear;
PrintLocation := GetPrintLocation(cxGrid1DBTableView1.DataController.GetDisplayText(cxGrid1DBTableView1Column3.DataBinding.DataController.FocusedRecordIndex,1));
showmessage(PrintLocation);
DBISAMQuery1.SQL.Clear;
DBISAMQuery1.SQL.Add(Format(C_Query_New, [PrintLocation]));
DBISAMQuery1.ExecSQL;
cxGrid1DBTableView2NEWMETHOD.PropertiesClass := TcxComboBoxProperties;
with TcxComboBoxProperties(cxGrid1DBTableView2NEWMETHOD.Properties) do
begin
if (DBISAMQuery1.RecordCount > 0) then
begin
while not DBISAMQuery1.Eof do
begin
(TcxComboBoxProperties(cxGrid1DBTableView2NEWMETHOD.Properties)).Items.Add(DBISAMQuery1.FieldByName('NewMethod').AsString);
DBISAMQuery1.Next;
end;
end;
end;
cxGrid1DBTableView2NEWMETHOD.DataBinding.FieldName := 'NEW METHOD';
DBISAMQuery1.SQL.Clear;
finally
FreeAndNil(DBISAMQuery1);
end; 
end;

end;

Open in new window

0
renjitkumar
Asked:
renjitkumar
  • 6
  • 3
  • 3
1 Solution
 
Ephraim WangoyaCommented:

Not there, use the ComboBox OnInitPopup event instead
Set the Edit properties at designtime, there is no need to do it in code

procedure TForm2.cxGrid1DBTableView2NEWMETHODInitPopup(Sender: TObject)
begin
  //your stuff

end;

the sender will be of type TcxCustomComboBoxProperties
procedure TForm2.cxGrid1DBTableView2NEWMETHODInitPopup(Sender: TObject)
const 
C_Query_New = 'select NewMethod from "C:\RAPID\RPFILES\PrintLocation.db4" where PrintLocationName = ''%0:s''';
var 
  PrintLocation : String;
  ComboBox: TcxCustomComboBoxProperties;
begin
try
ComboBox := (Sender as TcxCustomComboBox).Properties as TcxCustomComboBoxProperties;
ComboBox.Items.Clear
PrintLocation := GetPrintLocation(cxGrid1DBTableView1.DataController.GetDisplayText(cxGrid1DBTableView1Column3.DataBinding.DataController.FocusedRecordIndex,1));
showmessage(PrintLocation);
DBISAMQuery1.SQL.Clear;
DBISAMQuery1.SQL.Add(Format(C_Query_New, [PrintLocation]));
DBISAMQuery1.ExecSQL;
with ComboBox do
begin
if (DBISAMQuery1.RecordCount > 0) then
begin
while not DBISAMQuery1.Eof do
begin
(TcxComboBoxProperties(cxGrid1DBTableView2NEWMETHOD.Properties)).Items.Add(DBISAMQuery1.FieldByName('NewMethod').AsString);
DBISAMQuery1.Next;
end;
end;
end;
cxGrid1DBTableView2NEWMETHOD.DataBinding.FieldName := 'NEW METHOD';
DBISAMQuery1.SQL.Clear;
finally
FreeAndNil(DBISAMQuery1);
end; 
end;

end;

Open in new window

0
 
Geert GruwezOracle dbaCommented:
indenting ?
0
 
Geert GruwezOracle dbaCommented:
you free the query DBISAMQuery1,
but  ... don't create it in this procedure

gues you are getting access violation when entering this proc a second time ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
renjitkumarAuthor Commented:
ewangoya: No,it did'nt worked when i try doing that no items are getting populated do i need to set the combo box property at the design time of the grid column.No it is set both design time and in run time as stated in your code.

Geert_Gruwez: Thanks,was getting access violation and now i commented it out the code in finally block.
0
 
renjitkumarAuthor Commented:
ewangoya: oninitpopup event is not at all getting called when does this event will happen?my scenario is i have master record with 6 coulmns and under that detail records will be displayed with the expand and collapse functionality.Now the detail record 4 coulmn is set to combo box as the property ,now i want to pull up the data for every detail record based on the 4 th column in the master record.

Guess this depicts the overall scenario ? me tried out writing in getproperties and getpropertiesedit event but no luck .could you please assist me on this because i am new to express quantum grid control.

Thanks in advance.
0
 
Ephraim WangoyaCommented:

Sorry, I missed the expand part of your question, I'll look into it in a while
0
 
Geert GruwezOracle dbaCommented:
can you post a screenshot of what you are trying to do

combobox and detail below the row is 2 completely different things
0
 
Ephraim WangoyaCommented:

Ok,

first thing, how did you set up the OnInitPopup event.
This event will be called any time you click on a combobox. You set it up from the Object Inspector

second, you cant do this
PrintLocation := GetPrintLocation(cxGrid1DBTableView1.DataController.GetDisplayText(cxGrid1DBTableView1Column3.DataBinding.DataController.FocusedRecordIndex,1));
Just because a row is expanded does not mean the master view is at the correct parent record

third, I'm not sure why you have this code, if the field is not yet bound at this time, nothing will work in this piece of code
cxGrid1DBTableView2NEWMETHOD.DataBinding.FieldName := 'NEW METHOD';

fourth, use the Sender instance instead of typecasting the column
TcxComboBoxProperties(cxGrid1DBTableView2NEWMETHOD.Properties)

I'll try and fix your code in a few minutes

0
 
Ephraim WangoyaCommented:

Here, this should work so  long as your table has the requested data and you set up the OnInitPopup event properly

Note: Your method of reopening the query everytime is very inefficient it terms of speed, You should store the data in a memory dataset and when requested, just filter the records you want


procedure TForm3.cxGrid1DBTableView2NEWMETHODPropertiesInitPopup(Sender: TObject);
const
  C_Query_New = 'select NewMethod from "C:\RAPID\RPFILES\PrintLocation.db4" where PrintLocationName = ''%0:s''';
var
  PrintLocation : string;
  ComboBox: TcxCustomComboBoxProperties;
  GridRecord: TcxCustomGridRecord;
begin
  ComboBox := (Sender as TcxCustomComboBox).Properties as TcxCustomComboBoxProperties;
  ComboBox.Items.Clear;

  GridRecord := cxGrid1DBTableView1.MasterGridRecord;
  PrintLocation := GetPrintLocation(GridRecord.Values[cxGrid1DBTableView1Column3.Index]);
  if PrintLocation = '' then
    Exit;

  DBISAMQuery1.Close;
  try
    DBISAMQuery1.SQL.Clear;
    DBISAMQuery1.SQL.Add(Format(C_Query_New, [PrintLocation]));
    //DBISAMQuery1.ExecSQL; execsql is used for statements that dont return a resultset
    DBISAMQuery1.Open;
    while not DBISAMQuery1.Eof do
    begin
      ComboBox.Items.Add(DBISAMQuery1.FieldByName('NewMethod').AsString);
      DBISAMQuery1.Next;
    end;
  finally
    DBISAMQuery1.Close;
    DBISAMQuery1.SQL.Clear;
  end;
end;

Open in new window

SelectInitPopup.png
0
 
Ephraim WangoyaCommented:

Disregard the method I showed you using OnInitPopup. I tested that and it will be extremely slow since you have to reload everytime the combobox is pressed. A much better way is to use the DetailExpand event. This is called only once when the child tab is expanded

So this here is a better solution
procedure TForm3.cxGrid1DBTableView1DataControllerDetailExpanded(
  ADataController: TcxCustomDataController; ARecordIndex: Integer);
const
  C_Query_New = 'select NewMethod from "C:\RAPID\RPFILES\PrintLocation.db4" where PrintLocationName = ''%0:s''';
var
  PrintLocation : string;
  ComboBox: TcxCustomComboBoxProperties;
begin
  ComboBox := cxGrid1DBTableView2NEWMETHOD.Properties as TcxCustomComboBoxProperties;
  ComboBox.Items.Clear;

  //You can check if the value is null first
  PrintLocation := ADataController.Values[ARecordIndex, cxGrid1DBTableView1Column3.Index];
  PrintLocation := GetPrintLocation(PrintLocation);
  if PrintLocation = '' then
    Exit;
      
  DBISAMQuery1.Close;
  try
    DBISAMQuery1.SQL.Clear;
    DBISAMQuery1.SQL.Add(Format(C_Query_New, [PrintLocation]));
    //DBISAMQuery1.ExecSQL; execsql is used for statements that dont return a resultset
    DBISAMQuery1.Open;
    while not DBISAMQuery1.Eof do
    begin
      ComboBox.Items.Add(DBISAMQuery1.FieldByName('NewMethod').AsString);
      DBISAMQuery1.Next;
    end;
  finally
    DBISAMQuery1.Close;
    DBISAMQuery1.SQL.Clear;
  end; 
end;

Open in new window

0
 
Ephraim WangoyaCommented:

Here is a simple example
Unit3.dfm
Unit3.pas
0
 
renjitkumarAuthor Commented:
Thanx much needed one,task accomplished
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now