Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Empty DataGrid renders funny when custom columns added
5 replies. Latest Post by SilverlightWebApps on September 12, 2008.
(0)
Silverli...
Member
46 points
49 Posts
09-01-2008 6:04 PM |
I'm working on a demo project that involves a datagrid. When AutoGenerateColumns is set to true the datagrid looks fine whether ItemsSource is set to null or to real data. However when I set AutoGenerateColumns to False and define custom columns, the grid only shows a partial border when ItemsSource is set to null. Once I set ItemsSource to real data it looks fine again. How can I get the empty grid to render normally -- i.e. have a full border not border on the left hand side and the right hand half of the border blanked out.
<my:DataGrid Margin="8,283,51,87" AutoGenerateColumns="False" x:Name="ResultsGrid" > <my:DataGrid.Columns> <my:DataGridTextColumn Header="Test Item 1" DisplayMemberBinding="{Binding TestItem1}"/> <my:DataGridTextColumn Header="Test Item 2" DisplayMemberBinding="{Binding TestItem2}"/> </my:DataGrid.Columns> </my:DataGrid>
duefectu
Participant
786 points
241 Posts
09-01-2008 6:48 PM |
Try setting Width and Height properties for the DataGrid???
Yi-Lun L...
All-Star
25052 points
2,747 Posts
09-03-2008 3:28 AM |
Hello, this is by design for Beta 2. But in RTW, the behavior may change, so that even if your data source is empty, as long as you have defined the columns, the columns will be displayed, just there're 0 rows. In Beta 2, the only workaround I can think is to create a fake data source which contains one item, and in the LoadingRow event handler, you hide the first row after data is bound.
private bool fakeData;
List<Data> source = new List<Data>();source.Add(new Data() { Text = "aaa" });fakeData = true;dg.ItemsSource = source;
private void dg_LoadingRow(object sender, DataGridRowEventArgs e){if (fakeData){e.Row.Visibility = Visibility.Collapsed;}}
Later when you have real data source, you set fakeData to false, or remove the LoadingRow event handler completely.
yifung
Contributor
3313 points
540 Posts
09-03-2008 8:07 PM |
The partial border is a bug in the Beta 2 template of the DataGrid. This has been fixed for RTM. In addition, Yi-Lun is correct, the RTM DataGrid will show the column headers even if you have no items to display.
09-04-2008 7:23 AM |
I can confirm that, I have the same "bug/effect" in a project that i'm developing now.
09-12-2008 11:44 PM |
The help you guys gave me above with DataGrid was incorporated into a step-by-step tutorial I wrote on how to build a datacentric silverlight web app that uses WCF and LINQ to submit and retreive data from a database. You can check it out at my blog at http://http://www.silverlightwebapps.com/Tutorials.aspx.