Thursday, June 5, 2014

Get Column Value from CxGrid Multiselect (DevExpress)

For this Delphi Tutorial, i will write the code how to get value from a column for the data that we select. In this Case, we can select data more than one, and then get the values from a column from data that we select.

first step, make an application with button, cxgrid component, and database Components.
this is for example :

Don't forget to enable Multiselect option on cxGridDBTableView OptionSelection :


Then, write this code on Button OnClick event :
procedure TForm1.Button1Click(Sender: TObject);var i : integer;    s : String;
begin
for i:=0 to cxGrid1DBTableView1.Controller.SelectedRowCount - 1 do   
begin
showmessage(cxGrid1DBTableView1.Controller.SelectedRows[i].Values[0]);
end;
end;
Try to run the application, click the button, and see the result.
If this code run perfectly, the application will show value from column for data that we select.

SelectedRows[i] mean index for data that we select.

Values[0] is index for column. For this code, we will get value from Column ID, since it index is 0. You can change the index base on column you want to get the value.

1 comments:

avatar

This comment was so great. Thanks a lot.