How To Select Multiple Table Cells In 1 Or More Tables - Part 1
Here in the Support Department, we are frequently asked how to show the user which table cell has been selected or is currently active. We therefore decided it would be a good idea to make a sample application that shows how to select several table cells and change their attributes.
In the following example we will show you how to highlight table cells using the mouse. The cells do not have to be adjacent to each other nor do they even have to be in the same table.
If you build this into your application, the end-user can select several cells and set, for example, the table cell's border.
We use a class CTableData to store the values of the selected table cell. CellList is a collection that contains all selected table cells.
If a new table cell has been selected a new instance of CTableData is created. If this table cell has not already been selected, the BackColor will be changed and the cell will be added to the Collection CellList.
If TXTextControl1.TableAtInputPos <> 0 Then
Dim data As New CTableData
nIndex = IsSelected(data)
If (nIndex <> 0) Then
data.GetCol,txTableCellBackColor) = vbWhite
data.GetCol,txTableCellBackColor) = &HE0E0E0
Set data = Nothing
The function IsSelected checks if the currently selected table cell has been selected before.
Private Function IsSelected(data As CTableData) As Long
Dim nIndex As Long
nIndex = 1
For Each Cell In CellList
If (Cell.GetID = data.GetID And Cell.GetRow = data.GetRow
And Cell.GetCol = data.GetCol) Then
IsSelected = nIndex
nIndex = nIndex + 1
IsSelected = 0
Now the TableCellAttibutes can be changed for every cell in the Collection.
Download the demo project to see how it works in detail.
FREE Text Editor - Source Edit
Source Edit is a FREE text editor especially made for developers. It has fast syntax highlighting for several common computer languages. Download your free copy today at:
The Newsletter Team