Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Grid ctCheckBox
Thu, Aug 6 2015 11:32 PMPermanent Link

Trinione

How can the state of a grid column of ControlType ctCheckbox be accessed?

For instance, a user checks 3 checkboxes on the grid. How to find out which 3 they selected?
Fri, Aug 7 2015 2:00 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< How can the state of a grid column of ControlType ctCheckbox be accessed? >>

Is this a data-bound grid, or non-data-bound grid ?

If it's a data-bound grid, then you can simply read the applicable dataset column.  If it's not data-bound, then you can access the value via this property:

http://www.elevatesoft.com/manual?action=viewprop&id=ewb2&comp=TGridControl&prop=Rows

like this:

ShowMessage(MyGrid.Rows[10][MyBooleanColumn.Index]);

where 10 is the row to access (0-based).

Tim Young
Elevate Software
www.elevatesoft.com
Fri, Aug 7 2015 10:36 PMPermanent Link

Trinione

Tim:
<< Is this a data-bound grid, or non-data-bound grid ? >>

It is a data-bound grid. However, no field exist that I can access a boolean from. I would like to use a checkbox in the left most column to select the rows to work on.

For example,
       ID .| Details
[X] 1001 | Database info in Row 1
[  ] 1002 | Database info in Row 2
[X] 1003 | Database info in  Row 3
[  ] 1004 | Database info in Row 4

I tried creating a new field in the dataset, but that generates an error when I run and the Dataset object gets messed up and I need to remove and put the Dataset object from the start and reselect the events etc.

I the above example, How can I create a checkBox that appears with each databound grid row?

I am even trying to create a new 'virtual' column from the EDB database. Can a virtual Boolean field be created with a SELECT query??? That ought to work if its possible.

.
Sat, Aug 8 2015 5:56 AMPermanent Link

Trinione

Ok, I figured it out and posting to help others.

>> First create a virtual column in the dataset as type Boolean.

SELECT CAST(false AS BOOLEAN) AS chkState, * FROM TableName

>> Then, to set
procedure Tfrm.Grid1Click(Sender: TObject);
begin                  
 With DataSet1 do
 begin                       
   Update;
   Columns['chkState'].AsBoolean := Not Columns['chkState'].AsBoolean;
   Save;
 end;
end;

NOTE, with the upcoming Cell/Column OnClick event the code can be moved there and checked for chkState column being clicked.
Mon, Aug 10 2015 10:46 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Trinione,

<< I tried creating a new field in the dataset, but that generates an error when I run and the Dataset object gets messed up and I need to remove and put the Dataset object from the start and reselect the events etc. >>

What error message did you see ?  You should be able to add dataset columns without issue.  I just tried it here and it works fine.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Aug 10 2015 6:05 PMPermanent Link

Trinione

Sorry Tim, I was able to resolve my issue by creating a field in the query and using that. Can't recall the error at this time.
Image