Solved

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

Posted on 2011-03-10
12
1,784 Views
Last Modified: 2012-05-11
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
Comment
Question by:renjitkumar
[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
  • 6
  • 3
  • 3
12 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 50 total points
ID: 35095414

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
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 35095933
indenting ?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 35095966
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:renjitkumar
ID: 35097699
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
 

Author Comment

by:renjitkumar
ID: 35097808
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
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35097847

Sorry, I missed the expand part of your question, I'll look into it in a while
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 35098026
can you post a screenshot of what you are trying to do

combobox and detail below the row is 2 completely different things
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35102135

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
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35102935

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
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35104294

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
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35104474

Here is a simple example
Unit3.dfm
Unit3.pas
0
 

Author Closing Comment

by:renjitkumar
ID: 35107327
Thanx much needed one,task accomplished
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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