Solved

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

Posted on 2011-03-10
12
1,766 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:
ewangoya earned 50 total points
Comment Utility

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 36

Expert Comment

by:Geert Gruwez
Comment Utility
indenting ?
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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
 

Author Comment

by:renjitkumar
Comment Utility
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
Comment Utility
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:ewangoya
Comment Utility

Sorry, I missed the expand part of your question, I'll look into it in a while
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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:ewangoya
Comment Utility

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:ewangoya
Comment Utility

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:ewangoya
Comment Utility

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:ewangoya
Comment Utility

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

Author Closing Comment

by:renjitkumar
Comment Utility
Thanx much needed one,task accomplished
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now