Improve company productivity with a Business Account.Sign Up

x
?
Solved

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

Posted on 2011-03-10
12
Medium Priority
?
1,813 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
  • 6
  • 3
  • 3
12 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 200 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 39

Expert Comment

by:Geert G
ID: 35095933
indenting ?
0
 
LVL 39

Expert Comment

by:Geert G
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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 39

Expert Comment

by:Geert G
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…
Watch the working video to know how to import Outlook PST/OST files to Amazon WorkMail. Kernel released this tool which is very easy to use and migrate single or multiple PST and OST files to Amazon WorkMail. To know more about Kernel Import PST to …

580 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