Краткое описание:
У меня есть экземпляр класса CTreectrl
, где хранятся объекты, когда объект выбран, отображается соответствующий отчет списка для этого объекта.
Мне нужно настроить ширину столбцов экземпляра класса MyListCtrl, который происходит от CListCtrl
, чтобы данные в этих столбцах могли видеть пользователи без изменения размеров столбцов.Как перебирать элементы CListCtrl?
Как я подхожу свою задачу:
я реализовать метод InitColumnWidth, который вызывается, когда объект выбран из дерева
void COwnListCtrl::InitColumnWidth (unsigned const * defwidth, BOOL chars)
{
/* find the largest string in each column and set column width accordingly
so that user no longer need to manually adjust columns width */
RECT r;
GetClientRect (& r);
int* arrOfMaxColumnWidth = new int[NumCol]; // array where max length for columns will be stored
for (int i = 0; i < NumCol; ++i)
arrOfMaxColumnWidth[i] = 0; // initialize
tstring dataInColumn;
double Scale = (defwidth && chars) ? GetCharAveWidth (* GetFont()) : (r.right * 0.01);
int numberOfVisitedItems = 0;
do
{
dataInColumn = _T(""); // initialize
for (int col = 0; col < NumCol; ++col)
{
//DWORD const itemData = this->GetItemData(numberOfVisitedItems);
dataInColumn = this->GetSubItemString(this->GetItemData(numberOfVisitedItems), col);
/* 1-st varaint returns only first row of the list
because GetItemData always returns zero, but I need to visit all rows */
dataInColumn = this->GetSubItemString(numberOfVisitedItems, col);
/* 2-nd variant, works for most objects from CTreeCtrl, but for a few of them assertion is raised, system reports on the corrupted heap and application terminates*/
if (dataInColumn.length() > arrOfMaxColumnWidth[col])
arrOfMaxColumnWidth[col] = dataInColumn.length();
}
++numberOfVisitedItems;
}
while(dataInColumn.length() != 0); /* do{} while loop is used to get number of rows in the table
as long as an empty string is read, which means that all rows were read*/
for (int col = 0; col < NumCol; ++col)
int tmp = ColWidth[col] = arrOfMaxColumnWidth[col] * Scale;
ColWidth[0] = 100;
Нужна помощь!
это ISN 'работает, потому что this-> GetItemCount() возвращает 0, что может быть случай, что ??? –
Если у вас есть виртуальный список, вам нужно вызвать метод SetItemCount(). – cha
, поэтому мне нужно найти фрагмент кода, где элементы добавляются в мой список и вызывать там SetItemCount() с аргументом == количество элементов, которые я собираюсь добавить ??? –