在提供者內動態繫結資料行
更新:2007 年 11 月
請確定您真的需要動態資料行繫結。您可能會需要它,因為:
您並未在編譯時間定義資料列集資料行
您要支援可加入資料行的項目 (例如,書籤)
若要實作動態資料行繫結
移除程式碼中的任何一個 PROVIDER_COLUMN_MAP。
在使用者資料錄 (您的結構) 中,加入以下宣告:
static ATLCOLUMNINFO* GetColumnInfo(void* pThis, ULONG* pcCols);
實作 GetColumnInfo 函式。這個函式會安排資訊的儲存方式。您可能必須取得這個函式的屬性或其他資訊。您可能想要建立類似 COLUMN_ENTRY 巨集的巨集,以加入自己的資訊。
下列範例說明一個 GetColumnInfo 函式。
// Check the property flag for bookmarks, if it is set, set the zero // ordinal entry in the column map with the bookmark information. CAgentRowset* pRowset = (CAgentRowset*) pThis; CComQIPtr<IRowsetInfo, &IID_IRowsetInfo> spRowsetProps = pRowset; CDBPropIDSet set(DBPROPSET_ROWSET); set.AddPropertyID(DBPROP_BOOKMARKS); DBPROPSET* pPropSet = NULL; ULONG ulPropSet = 0; HRESULT hr; if (spRowsetProps) hr = spRowsetProps->GetProperties(1, &set, &ulPropSet, &pPropSet); if (pPropSet) { CComVariant var = pPropSet->rgProperties[0].vValue; CoTaskMemFree(pPropSet->rgProperties); CoTaskMemFree(pPropSet); if (SUCCEEDED(hr) && (var.boolVal == VARIANT_TRUE)) { ADD_COLUMN_ENTRY_EX(ulCols, OLESTR("Bookmark"), 0, sizeof(DWORD), DBTYPE_BYTES, 0, 0, GUID_NULL, CAgentMan, dwBookmark, DBCOLUMNFLAGS_ISBOOKMARK) ulCols++; } } // Next, set up the other columns. ADD_COLUMN_ENTRY(ulCols, OLESTR("Command"), 1, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szCommand) ulCols++; ADD_COLUMN_ENTRY(ulCols, OLESTR("Text"), 2, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szText) ulCols++; ADD_COLUMN_ENTRY(ulCols, OLESTR("Command2"), 3, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szCommand2) ulCols++; ADD_COLUMN_ENTRY(ulCols, OLESTR("Text2"), 4, 256, DBTYPE_STR, 0xFF, 0xFF, GUID_NULL, CAgentMan, szText2) ulCols++; if (pcCols != NULL) *pcCols = ulCols; return _rgColumns; }