공급자에서 열을 동적으로 바인딩
동적 열 바인딩이 실제로 필요한지 확인합니다. 다음과 같은 이유로 필요할 수 있습니다.
행 집합 열은 컴파일 시간에 정의되지 않습니다.
열을 추가하는 책갈피와 같은 요소를 지원합니다.
동적 열 바인딩을 구현하려면
코드에서 s
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; }