This is a migrated thread and some comments may be shown as answers.

Best Fit functionality

4 Answers 302 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 03 Apr 2014, 01:19 PM
Hi,
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

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Apr 2014, 10:35 AM
Hello Thomas,

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.

 
0
Thomas
Top achievements
Rank 1
answered on 10 Apr 2014, 08:36 AM
LoL, can't believe I didn't see the BestFit method itself. Thanks for the help!
0
Michael
Top achievements
Rank 1
answered on 13 Aug 2020, 08:53 PM

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

 

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Aug 2020, 10:03 AM
 Hello, Michael,


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

Tags
ListView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Thomas
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or