private void GetLargestTextExtent(DataListView dlv, int colNumber, ref int largestWidth) { int maxLen = -1; ListViewItem lvi = null; if (this.Items.Count >= 1) { if (colNumber >= 0 && colNumber < this.mColumns.Count) { using (Graphics g = this.CreateGraphics()) { int newWidth = -1; for (int nLoopCnt = 0; nLoopCnt < this.Items.Count; nLoopCnt++) { lvi = (ListViewItem)this.Items[nLoopCnt] as ListViewItem; if (lvi != null) { newWidth = (int)g.MeasureString(lvi.SubItems[colNumber].Text, this.Font).Width; } else { newWidth = 0; } if (newWidth > maxLen) { maxLen = newWidth; } } g.Dispose(); } } } largestWidth = maxLen; }
private void GetLargestColHdrTextExtent(DataListView dlv, int colNumber, ref int largestWidth) { if (this.Items.Count >= 1) { if (colNumber >= 0 && colNumber < this.mColumns.Count) { using (Graphics g = this.CreateGraphics()) { largestWidth = (int)g.MeasureString(this.mColumns[colNumber].Text, this.Font).Width; g.Dispose(); } } } }