Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF MVVM DataGrid
    <Grid>
        <DataGrid AutoGenerateColumns="False"
                  ItemsSource="{Binding Path=Database}">
            <DataGrid.Columns>
                <DataGridTextColumn Width="Auto" 
                                    Binding="{Binding Path=Integer}" 
                                    Header="String" />
                <DataGridTextColumn Width="Auto" 
                                    Binding="{Binding Path=String}" 
                                    Header="String" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
 
This is my Xaml example code to reproduce the problem... there is no code behind.
 
 
class DataGridViewModel
    {
        public class Data
        {
            #region properties
            public int Integer { get; set; }
            public string String { get; set; }
            public double Double { get; set; }
            #endregion
 
            #region instance constructors
            /// <summary>
            /// Initializes a new instance of the <see cref="Data"/> class.
            /// </summary>
            public Data(int i, double d, string s)
            {
                /* initializes all instance members */
                Integer = i;
                Double = d;
                String = s;
            }
            #endregion
        }
 
        private readonly List<Data> _database = new List<Data>(10);
 
        public IEnumerable<Data> Database
        {
            get { return _database; }
        }
 
        public DataGridViewModel()
        {
            /* initializes all instance members */
            _database.Add(new Data(1, 1.5, "test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1"));
            _database.Add(new Data(2, 2.5, "test2test2test2test2test2test2test2test2test2test2test2test2test2test2test2test2test2test2"));
            _database.Add(new Data(3, 3.5, "test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3"));
            _database.Add(new Data(4, 4.5, "test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4"));
            _database.Add(new Data(5, 5.5, "test5test5test5test5test5test5test5test5test5test5test5test5test5test5test5test5test5test5"));
            _database.Add(new Data(6, 6.5, "test6test6test6test6test6test6test6test6test6test6test6test6test6test6test6test6test6test6"));
            _database.Add(new Data(7, 7.5, "test7test7test7test7test7test7test7test7test7test7test7test7test7test7test7test7test7test7"));
            _database.Add(new Data(8, 8.5, "test8test8test8test8test8test8test8test8test8test8test8test8test8test8test8test8test8test8"));
            _database.Add(new Data(9, 9.5, "test9test9test9test9test9test9test9test9test9test9test9test9test9test9test9test9test9test9"));
            _database.Add(new Data(10, 10.5, "test10test10test10test10test10test10test10test10test10test10test10test10test10test10test10"));
        }
    }
 
this is the view model.
 

Problem: If I set the column width to "auto" the horizontal scroll bar shows as wished but if the window gets to big i can't select a row in the last empty column.
 
If I set the column width to "*" the empty column is removed and i can select a row everywhere in the data grid. Now I have a Problem with the horizontal scroll bar, which isn't shown or if it gets shown some times i can't scroll and my text gets cut.
 
Greetings
Posted 27-May-13 5:17am
Schwimo158
Edited 27-May-13 5:19am
v2
Comments
govardhan4u at 28-May-13 2:23am
   
try to keep use the horizontal scroll bar poperty or keep that grid inside the scrollview tags

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 BillWoodruff 260
3 Shweta N Mishra 244
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 27 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100