+unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
+{
+ if ( m_colsBestWidths[idx] != 0 )
+ return m_colsBestWidths[idx];
+
+ const unsigned count = m_clientArea->GetRowCount();
+ wxDataViewColumn *column = GetColumn(idx);
+ wxDataViewRenderer *renderer =
+ const_cast<wxDataViewRenderer*>(column->GetRenderer());
+
+ int max_width = 0;
+
+ if ( m_headerArea )
+ {
+ max_width = m_headerArea->GetTextExtent(column->GetTitle()).x;
+
+ // Labels on native MSW header are indented on both sides
+ max_width += wxRendererNative::Get().GetHeaderButtonMargin(m_headerArea);
+ }
+
+ for ( unsigned row = 0; row < count; row++ )
+ {
+ wxDataViewItem item = m_clientArea->GetItemByRow(row);
+
+ wxVariant value;
+ GetModel()->GetValue(value, item, column->GetModelColumn());
+ renderer->SetValue(value);
+
+ max_width = (unsigned)wxMax((int)max_width, renderer->GetSize().x);
+ }
+
+ if ( max_width > 0 )
+ max_width += 2 * PADDING_RIGHTLEFT;
+
+ const_cast<wxDataViewCtrl*>(this)->m_colsBestWidths[idx] = max_width;
+ return max_width;
+}
+