CGXODBCGrid::AttachForeignTable

void AttachForeignTable(ROWCOL nCol, CGXDynamicRecordset* pSet, UINT nKeyCol, UINT nDispCol, BOOL bDispAllCols, BOOL bDisplayHeader);

nCol

Specifies the column id in your grid that contains key values.

pSet

Pointer to the recordset with the foreign table (or query).

nKeyCol

The zero-based column id that specifies the column in the foreign recordset with the key values that match the values in the grid column.

nDispCol

The zero-based column id that specifies the column in the foreign recordset to be used for displaying the cell text in the grid.

bDispAllCols

TRUE if you want to display all columns of the foreign recordset in the drop-down list; FALSE if you only want to drop down the text that will be displayed in the cell (column nDispCol).

bDisplayHeader

TRUE if the field names of the columns in the foreign recordset shall be displayed as column headers in the drop-down list; FALSE if no headers shall be displayed.

Remarks

This method lets you attach a table with a foreign key to a column.

The method will open the given recordset and loop through all rows and build up the choice list. This choice list and the GX_IDS_CTRL_TABBED_COMBOBOX cell type will be assigned to the column base style, so that all cells in the column can drop down the foreign table. See CGXTabbedComboBox for a discussion about tabbed combo boxes.

For example, you could attach a foreign table to the column and display descriptive text for a key (e.g., student name instead of student id).

Note

Once you have attached a foreign table to a column with AttachForeignTable outside changes in this foreign table will not update the choice list. In order to update the column with new changes you have to call AttachForeignTable again.

Example:

      // attach the table to the column
      CString strSQL = _T("Select StudentId, Name From Student");
      UINT nKeyCol = 0; // Student Id
      UINT nDisplayCole = 1; // Display the name
      CGXDynamicRecordset set(GetDocument()->m_pdb);
      set.SetSqlQuery(strSQL);
      ResetCurrentCell();
      AttachForeignTable(nCol, &set,
         nKeyCol, nDispCol, TRUE /* Show all cols */, TRUE /* Show header */);
      ResizeColWidthsToFit(CGXRange(GetHeaderRows()+1, nCol));
   }

ee AlsoCGXTabbedComboBox

CGXODBCGrid

 Class Overview |  Class Members