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

Fit Columns only 99%

5 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kitty
Top achievements
Rank 1
Kitty asked on 01 Oct 2014, 05:03 PM
Hi

            RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
            or
            RadGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill

            is it possible to fit 100%?

Thank You

5 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 06 Oct 2014, 09:53 AM
Hello Kitty,

Thank you for writing.

Can you please clarify for me why you think that the columns do not fit at 100%? As far as I can see they are taking the full space available. You can see that from the attached image.

Looking forward to your reply.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Kitty
Top achievements
Rank 1
answered on 07 Oct 2014, 01:06 PM
Hi George

Sorry, it is not 99%,
it is 101% (over fit),
because the hscrollbar can still moving, when horizoned scrolling.

Thank You
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Oct 2014, 01:22 PM
Hello Kitty,

Thank you for writing.

Horizontal scrolling is turned on by default. However, when AutoSizeColumnsMode is set to Fill, columns are resized to fit the available space in RadGridView. In this mode, horizontal scroll bar is not supposed to be displayed. Use the following code to change the AutoSizeColumnsMode property to be applicable with horizontal scroll bar:
this.radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None; 

You can control the scrollbar visibility by VerticalScrollState and HorizontalScrollState properties of RadGridView. You can set them to AlwaysHide, AlwaysShow, and AutoHide (default). If your requirement is fill the columns to 100% and force the horizontal scroll bar to be shown without the ability to move it, you can use the TableElement.HScrollBar.ValueChanged event and set the TableElement.HScrollBar.Value property to 0‚Äč:
private void Form1_Load(object sender, EventArgs e)
{
    this.order_DetailsTableAdapter.Fill(this.nwindDataSet.Order_Details);
 
    radGridView1.HorizontalScrollState = Telerik.WinControls.UI.ScrollState.AlwaysShow;
    radGridView1.VerticalScrollState = Telerik.WinControls.UI.ScrollState.AlwaysHide;
    radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
 
    radGridView1.TableElement.HScrollBar.Minimum = this.radGridView1.TableElement.HScrollBar.Maximum = 0;
    radGridView1.TableElement.HScrollBar.ValueChanged += HScrollBar_ValueChanged;
}
 
private void HScrollBar_ValueChanged(object sender, EventArgs e)
{
    if (this.radGridView1.AutoSizeColumnsMode == Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill)
    {
        this.radGridView1.TableElement.HScrollBar.Value = 0;
    }
}

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
Kitty
Top achievements
Rank 1
answered on 11 Oct 2014, 05:37 AM
Hi Desislava

Thank You for your help

columns fill perfect.. thanks again

also
is it possible to maintain grid lines even if the grid is not full?
(example: ComponentOne C1TrueDBGrid EmptyRows = True)

Thank You
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Oct 2014, 04:04 PM
Hello Kitty,

Thank you for writing back.

By default our RadGridView does not display empty rows. Hence, it shows grid lines only for the data rows. However, you can add empty rows to the data source if the RadGridView is bound mode, or add empty rows directly to the RadGridView.Rows collection for unbound mode. Thus, you will force the grid lines to be shown:
this.radGridView1.DataSource = this.orderDetailsBindingSource;
this.order_DetailsTableAdapter.Fill(this.nwindDataSet.Order_Details);
 
this.nwindDataSet.Order_Details.Rows.Clear();
 
this.radGridView1.Columns[0].IsVisible = false;
this.radGridView1.Columns[1].IsVisible = false;
for (int i = 0; i < 20; i++)
{
    this.nwindDataSet.Order_Details.Rows.Add(i, i);
}

I hope this information helps. If you have any additional questions, please let me know.

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.

 
Tags
GridView
Asked by
Kitty
Top achievements
Rank 1
Answers by
George
Telerik team
Kitty
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or