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
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 ?
renjitkumar
ASKER
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.
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.
Ephraim Wangoya
Sorry, I missed the expand part of your question, I'll look into it in a while
Geert G
can you post a screenshot of what you are trying to do
combobox and detail below the row is 2 completely different things
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
Ephraim Wangoya
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;
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;