I'm trying to use the best fit functionality for ListViews. Im using a list as the datasource like this:
radListView.DataSource = List<Myclass>
and in the BindingCompleted event i do the following:
foreach (ListViewDetailColumn c in rlv.Columns)
{
c.AutoSizeMode = ListViewBestFitColumnMode.AllCells;
}
The columns are not resized at all. Could you provide me with an example of how to use this feature ?
/Thomas
4 Answers, 1 is accepted
Thank you for writing.
RadListView has a built-in mechanism to increase or decrease the width of one or all columns in a way that makes all the text inside that column cells visible. You can enable this mechanism via the DetailListViewElement.BestFitColumns method or using ListViewDetailColumn.BestFit one. In both cases it is necessary to have data in the listview in order to obtain correct column width. Here is a sample code snippet that you may follow to fit the columns:
public
Form1()
{
InitializeComponent();
this
.radListView1.DataSource =
this
.customersBindingSource;
this
.radListView1.ViewType = ListViewType.DetailsView;
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
this
.customersTableAdapter.Fill(
this
.nwindDataSet.Customers);
foreach
(ListViewDetailColumn c
in
this
.radListView1.Columns)
{
c.BestFit();
}
}
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Hello,
I know this post is a bit older, but I found it while looking for my issue. I have a RadListView where I have set the BestFit, but it does not appear to take into account the header text. The columns definitely resize, but some of the column data is smaller than the header text and it ends up squishing the header text. I've tried the BestFit for both the DetailListViewElement and the ListViewDetailColumn and they both seem to do the same thing. Note the last 4 columns below. This case is using
((DetailListViewElement)radListView1.ListViewElement.ViewElement).BestFitColumns();
Thanks for any help.
Mike
You can customize the execution of the algorithm of a concrete column by setting its AutoSizeMode property if the desired column. There are the following options:
- ListViewBestFitColumnMode.None - The column width does not automatically adjust.
- ListViewBestFitColumnMode.AllCells - The column width adjusts to fit the contents all cells in the column.
- ListViewBestFitColumnMode.DataCells - The column width adjusts to fit the contents of the data cells.
- ListViewBestFitColumnMode.HeaderCells - The column width adjusts to fit the contents of the header cell.
The default value is ListViewBestFitColumnMode.DataCells. That is why only the data cells content is considered when calculating the necessary column's width.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik