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

Gettting extra column in Radgridview

9 Answers 224 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chetan
Top achievements
Rank 1
Chetan asked on 14 Oct 2010, 06:04 PM
Hello Telerik Team,

While binding reocords in grid i am getting one extra column.

Is it posible to remove it?

Please let me know how to do this.

Screen shot has been attached with this thread.

and code is

<

 

 

telerik:RadGridView x:Name="RadGrid" AutoGenerateColumns="False">

 

 

 

 

<telerik:RadGridView.Columns>

 

 

 

 

<telerik:GridViewToggleRowDetailsColumn />

 

 

 

 

<telerik:GridViewDataColumn Header="Day" DataMemberBinding="{Binding Day}" />

 

 

 

 

<telerik:GridViewDataColumn Header="AllocatedHours" DataMemberBinding="{Binding AllocatedHours}" />

 

 

 

 

<telerik:GridViewDataColumn Header="RemainingHours" DataMemberBinding="{Binding RemainingHours}" />

 

 

 

 

<telerik:GridViewDataColumn Header="CalculatedHours" DataMemberBinding="{Binding CalculatedHours}" />

 

 

 

 

<telerik:GridViewDataColumn Header="NotCalculatedHours" DataMemberBinding="{Binding NotCalculatedHours}" />

 

 

 

 

</telerik:RadGridView.Columns>

 

 

 

 

 

</telerik:RadGridView>

 

9 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 14 Oct 2010, 06:08 PM
Hello Chetan,

 This is not an extra column, but simply empty space not taken up by any other column. If you'd like your last column to stretch all the way to the end, simply set its Width property to '*' (star) in XAML.

Best wishes,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mike
Top achievements
Rank 2
answered on 29 Jul 2011, 05:55 PM
The proposed solution sucks. Why should we have to stretch the last column into infinity? I want my last column to be the last thing to display without a hokey kludge like this.
0
Maya
Telerik team
answered on 01 Aug 2011, 07:04 AM
Hello Mike,

The fact that you get an extra space after the last column is by design and it may be removed either by setting the Width of the last column to "*" as suggested previously or by setting the ColumnWidth property of the grid to "*". In both cases you make the columns fill the whole available space. 
However, yet another approach would be to predefine the template of the RadGridView and set the VerticalAlignment and HorizontalAlignment properties of the GridViewVirtualizingPanel to "Left" and "Top" respectively. I am sending you a sample project illustrating this approach. 

 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Mike
Top achievements
Rank 2
answered on 01 Aug 2011, 04:07 PM

Maya,

Let me explain a bit more about the requirements I'm trying to meet.

  • The RadGridView needs to reside inside a scroll viewer. I have a grid inside the scroll viewer and the RadGridView in a cell within that so I can position some buttons in a cell below the RadGridView. This whole thing needs to scroll both vertically and horizontally if a user resizes the browser to something like 640x480 which gives them an even smaller viewable region within the browser. We have users worldwide with anything from LCD displays down to old CRT displays that only handle 640x480. They have to be able to see the contents of the RadGridView and the buttons.
  • It needs to show only the defined columns.
  • All of the columns should fit within the displayed area with MinWidth values that prevent the grid from shrinking too much (hence the scroll viewer for when there isn't enough real estate.)
 
Your example has a fixed page size, which we can't have. I placed the RadGridView into a scroll viewer and am seeing the same issues I'm trying to address that caused my frustrated little rant. Placing a Width="*" in the last column does get rid of the extra gunk on the end of the grid view, but causes the column to stretch off of the screen to quite a ways since there is no fixed width. If I try to set a MaxWidth value for the last column, the width won't expand as far, but the gunk comes back.
I've fiddled with a DataGrid as well, thinking that I may need to revert to a standard control, but it has the same behavior.

So thanks for the response and if you ever come up with something that addresses this. Let me know. For now, I'll just tell our users "we are working on it" and it will be in a "future" release. They won't be happy, but will live with it.

Mike
0
Maya
Telerik team
answered on 01 Aug 2011, 06:20 PM
Hi Mike,

Generally, this behavior is by design and probably it will not be changed in the near future. As you correctly mentioned that is the behavior of the DataGrid as well. What you may also try is to set the Width of the columns proportionally. For example:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                            Header="Est." Width="2*"
                                            DataFormatString="{}{0:yyyy}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
                                            Header="Stadium" Width="4*"
                                            DataFormatString="{}{0:N0}"/>

Thus the columns will occupy the whole place, but they will be sized in a certain proportion. You may take a look at this article for further reference.
 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Mike
Top achievements
Rank 2
answered on 01 Aug 2011, 06:32 PM
Maya,

I already tried this approach. Since the page size is not set, the columns expand to an unusable width. See the attached image. I'v also included the markup.

<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
    <StackPanel>
 
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
 
            <telerik:RadGridView Margin="8" ItemsSource="{Binding Collection}" Style="{StaticResource RadGridViewStyle}" AutoGenerateColumns="False" IsReadOnly="True"
                    RowIndicatorVisibility="Collapsed" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" ScrollMode="Deferred">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Property 1" DataMemberBinding="{Binding Path=Property1}" TextWrapping="Wrap"  Width="7*"/>
                    <telerik:GridViewDataColumn Header="Property 2" DataMemberBinding="{Binding Path=Property2}" TextWrapping="Wrap" Width="3*" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
 
        </ScrollViewer>
 
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <sdk:DataGrid Margin="8" ItemsSource="{Binding Collection}" AutoGenerateColumns="False" IsReadOnly="True" VerticalContentAlignment="Stretch"
                    ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Header="Property 1" Binding="{Binding Path=Property1}" />
                    <sdk:DataGridCheckBoxColumn Header="Property 2" Binding="{Binding Path=Property2}" Width="*" MaxWidth="150" />
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
        </ScrollViewer>
 
    </StackPanel>
</Grid>

Mike
0
Maya
Telerik team
answered on 02 Aug 2011, 06:44 AM
Hi Mike,

You get this behavior because you define your RadGridView in a control that measures with infinity - in this case both the ScrollViewer and the StackPanel are such. I may recommend you to define the RadGridView in a Grid for example. In this case the columns will not be extended to such level event when set to "*"/ "7*:
Furthermore, when you define a virtualized control (like RadGridView) in another one that measures with infinity, you loose the virtualization, e.i. if you handle a lot of data, you will probably get your performance degraded. 
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Karthik Reddy
Top achievements
Rank 1
answered on 24 Jul 2015, 06:24 PM

Hi,

I am binding a RadGridView to a dynamic data source that can contain multiple numbers of columns. A blank column is always being displayed to the right of the grid and this column can not be selected. I am not adding this column in code and cannot see this column in the columns collection of the grid. I have googled and found a solution as adding column width as "*". But if i do so my window is going to infinite size as i have not defined max width(Reason for not defining max width is they are using at multiple places in the project).

0
Dimitrina
Telerik team
answered on 27 Jul 2015, 07:31 AM
Hello,

It seems RadGridView is measured with infinity in this scenario. Generally, I would not recommend you defining RadGridView (or any virtualized control) in panels like ScrollViewer, DockPanelStackPanel or Grid with Row.Height=Auto as they measure its content with infinity and the UI virtualization of the grid will be broken. Consequently, there will be also performance degradation.

You can place RadGridView in a Grid with Row.Height="*" instead. You can also refer to the online documentation explaining how the UI virtualization works. 

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Chetan
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Mike
Top achievements
Rank 2
Maya
Telerik team
Karthik Reddy
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or