TMSFMXGrid: Check checkboxes in code?

I'm trying to use the TMSFMXGrid to represent a list of names where some of them are checked. I have the code finished to show the list, check and uncheck the items and export this list to the place I need it to go. But I need a way to open the list initially with some of the items already checked. I have a stringlist that contains the names that need to be checked, but I can't seem to find a way to check the items. In OnGetCellData() I do not have a reference to a Cell. And when I check a checkbox in OnGetCellProperties() I'm unable to uncheck the names with the mouse. How can I check the checkboxes from within the code? And where? Here are the events I wrote up until now:




// This works; I would like to also check the boxes here that need to be checked,
// but I do not have a reference to the Cell 
OnGetCellData(TObject *Sender, int ACol, int ARow, UnicodeString &CellString)
{
	if (ARow == 0)
		CellString = "Available groups";
	else
		CellString = AvailableGroupsList->Strings[ARow - 1];
}
//---------------------------------------------------------------------------


// This seems to work great if I do not try to check items from within the code

OnCellCheckBoxClick(TObject *Sender,  int ACol, int ARow, TFmxObject *Cell)
{
	TTMSFMXCheckGridCell *ACell;
	int SubscribedGroupLocation;
	String GroupName;


	ACell = (TTMSFMXCheckGridCell *) Cell;


	if (ACell->CheckBox->IsChecked)
		SubscribedGroupsList->Add(AvailableGroupsList->Strings[ARow - 1]);
	else
	{
		GroupName = AvailableGroupsList->Strings[ARow - 1];
		SubscribedGroupLocation = SubscribedGroupsList->IndexOf(GroupName);
		if (SubscribedGroupLocation > -1)
			SubscribedGroupsList->Delete(SubscribedGroupLocation);
	}
}
//---------------------------------------------------------------------------


// This does not work; It makes it impossible to uncheck names with the mouse

GetCellProperties(TObject *Sender, int ACol, int ARow, TFmxObject *Cell)
{
	if (ARow == 0)
		return;


	TTMSFMXCheckGridCell *ACell;


	ACell = (TTMSFMXCheckGridCell *) Cell;


	if (SubscribedGroupsList->IndexOf(AvailableGroupsList->Strings[ARow - 1]) != -1)
		ACell->CheckBox->IsChecked = true;
	else
		ACell->CheckBox->IsChecked = false;
}
//---------------------------------------------------------------------------

if you added the checkboxes with AddCheckBoxColumn you can change the value with TMSFMXGrid1.Booleans[Col, Row];


Kind Regards, 
Pieter

Hi Pieter,


Thank you. That worked. I now check all the boxes while populating the grid in the beginning. Which makes a lot more sense.



		AvailableGroupsGrid->RowCount = AvailableGroupsList->Count + 1;
		for (int i=0; i<AvailableGroupsList->Count; i++)
		{
			if (SubscribedGroupsList->IndexOf(AvailableGroupsList->Strings) != -1)
				AvailableGroupsGrid->Booleans[0][i+1] = true;
		}