State property is used as an indicator for which items are selected or checked.
For example, for each member of the Items array, we use State to determine whether the checkbox is selected (cbChecked), cleared (cbUnchecked), or dimmed (cbGrayed).
Note: cbGrayed corresponds to the indeterminate state.
State combines the information provided by the Boolean Checked property and the Boolean ItemEnabled property:
- When Checked is True, State is cbChecked. However, when Checked is False, State may be either cbUnchecked or cbGrayed.
- When State is cbGrayed, ItemEnabled is False. However, ItemEnabled may also be False when State is cbUnchecked or cbChecked.)
Another example of a State use case is in Draw Grid creation. State will show us the selected cell in the created grid or table.
Here is the working example of the implementation of State in Draw Grid creation:
def grdTestDrawCell(Sender, Col, Row, Rect, State):
if gdSelected in State:
Sender.Canvas.Brush.Color = clBlue # 0x00ff0000 # blue
Sender.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, "%d @ %d" % (Col, Row))
def grdTestSelectCell(Sender, Col, Row, CanSelect):
if Col == 2 and Row == 2:
CanSelect.Value = False
grdTest.OnDrawCell = grdTestDrawCell
grdTest.OnSelectCell = grdTestSelectCell
See the complete code here.