Change Cell Background Color in a Table Control
To just simply change the background color of all cells in Table, Listboxes, Multicolumn List boxes and Tree Controls, follow the below procedure:
- Use the CellBGColor property to set the color to a cell.
- Use ActiveCell Property to set the row and column of the cell that needs this change.
- In the below LabVIEW examples, the background color of all the cells (-2,-2 indicates all cells) are set with a specific color (white).
- This piece of code is important as part of initialization, to reset the color to original.
Listed here are a few cases where cell background color is changed due to an action(click) by the user in the TableControl.
LabVIEW Example 1
In this LabVIEW example, the user can click anywhere between the first and tenth row and change its background color. If the user clicks anywhere beyond the tenth row, the cell background color does not change. In this code, we are limiting the user to click within the tenth row.
- An event structure is used to capture an user action like a mouse click by user in one of the table cells or on the stop button.
- 3 event cases: Timeout, TableControl:Mouse Down, Stop.
- SelStart property of TableControl is used to obtain the index(row,col) of the click.
- The TRUE case is empty in the TableControl event
LabVIEW Example 2
In this LabVIEW example, the user can click anywhere in a row and the first cell of that row will get highlighted indicating the selection of that row. This piece can be used in places where the user needs to select specific rows of interest (e.g: select channels for acq, rows of data for processing..etc). In this code also we are limiting the user to click within the tenth row.