locked
Lightswitch Custom Silverlight Datagrid Header and Data Not Displaying RRS feed

  • Question

  • Hello all,

    I have created a custom Silverlight control in Lightswitch that will allow me to print data from a screen (using the following link as a guide: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/3/Printing-With-LightSwitch.aspx).  I am using Grids and Text Block controls to display the parent screen entity data within the print control, but have a group of data (a child entity of the screen entity) that can have 1 or more rows, so I wanted to use a data grid to display those.  When I consume the control in LightSwitch, all the parent entity data is displayed correctly, but the data grid seems to be drawing out enough space to display the data, but remains blank.  I can click in the data grid control and the necessary columns and number of rows seem to be there.  For example, if the child entity is supposed to have 7 columns and 2 rows of data, I can highlight the columns and rows, but nothing shows up.

    Even weirder, if I switch from the Cosmopolitan theme to the Blue theme, the column headings will appear, but still no data.

    Here is my .xaml code for the datagrid.  

    <sdk:DataGrid x:Name="order_description"
                          Height="Auto"
                          Width="624"
                          
                          AutoGenerateColumns="False"
                          Grid.Row="1"
                          Grid.Column="7"
                          HorizontalScrollBarVisibility="Hidden"
                          ItemsSource="{Binding Path=Screen.ChildEntity, Mode=TwoWay}"
                          Background="Transparent">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.quantity}" DisplayIndex="0" Header="Quantity" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.Breed}" DisplayIndex="1" Header="Breed" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.Sex}" DisplayIndex="2" Header="Sex" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.age}" DisplayIndex="3"  Header="Age" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.weightMin}" DisplayIndex="4"  Header="Weight" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.Color}" DisplayIndex="5"  Header="Color" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Path=Value.other}" DisplayIndex="6" Header="Other" MaxWidth="89" Width="89"/>
                </sdk:DataGrid.Columns>
                
            </sdk:DataGrid>

    Can anybody help with this?  Please let me know if you need more info

    Monday, July 15, 2013 10:00 PM

Answers

  • Thanks for your replies AllenAdams and babloo1436!

    Weirdly, I was able to get my data to display in the datagrid by binding the ItemsSource to the full path of the child entity and binding each column to the just the property name.  For example:

    		ItemsSource="{Binding Path=Screen.ChildEntity, Mode=TwoWay}">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Binding="{Binding quantity}" DisplayIndex="0" Header="Quantity" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Breed}" DisplayIndex="1" Header="Breed" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Sex}" DisplayIndex="2" Header="Sex" MaxWidth="89" Width="89"/>
    and so on.

    However, the column headings do not appear while using the Cosmopolitan theme, but do when I switch to the Blue Theme.  Allen, unfortunately the ColumnHeaderHeight Property didn't help on the Cosmopolitan theme.

    Has anybody else had a problem with displaying datagrid columns while using the Cosmopolitan theme?

    • Marked as answer by RaySanders7 Thursday, June 26, 2014 3:12 PM
    Wednesday, July 17, 2013 5:17 PM

All replies

  • The hardest thing about custom controls, I think, is that IntelliSense usually cannot help with the databinding.  So, are you sure that

    ItemsSource="{Binding Path=Screen.ChildEntity, ..."}

    is what your grid should bind to?  Or is it something like Screen.Order.Description (just a guess).

    The SilverLight grid has a ColumnHeaderHeightProperty that you can set, maybe explicitly defining that would force the Cosmopolitan theme to show them.

    For some more examples of custom control datagrid use in LightSwitch (Telerik's grid, however), check out the Advanced LightSwitch Special blog and Telerik's GridView in LightSwitch tutorials.

    Tuesday, July 16, 2013 7:40 AM
  • Hi Ray

    Go through the below post. May this will help you to shut your issue.

    Custom DataGrid Coloring each row based on a value

    HTH

    Regards


    Rashmi Ranjan Panigrahi
    www.lightswitchspecial.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.

    Tuesday, July 16, 2013 12:42 PM
  • Thanks for your replies AllenAdams and babloo1436!

    Weirdly, I was able to get my data to display in the datagrid by binding the ItemsSource to the full path of the child entity and binding each column to the just the property name.  For example:

    		ItemsSource="{Binding Path=Screen.ChildEntity, Mode=TwoWay}">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Binding="{Binding quantity}" DisplayIndex="0" Header="Quantity" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Breed}" DisplayIndex="1" Header="Breed" MaxWidth="89" Width="89"/>
                    <sdk:DataGridTextColumn Binding="{Binding Sex}" DisplayIndex="2" Header="Sex" MaxWidth="89" Width="89"/>
    and so on.

    However, the column headings do not appear while using the Cosmopolitan theme, but do when I switch to the Blue Theme.  Allen, unfortunately the ColumnHeaderHeight Property didn't help on the Cosmopolitan theme.

    Has anybody else had a problem with displaying datagrid columns while using the Cosmopolitan theme?

    • Marked as answer by RaySanders7 Thursday, June 26, 2014 3:12 PM
    Wednesday, July 17, 2013 5:17 PM
  • I too am having the same problem with a custom control based on the datagrid. The Cosmopolitan theme is definitely killing the display of the column headers, whether you are using autogeneratecolumns, or binding them individually.  Very irritating, especially since I don't like the Blue theme.

    I suspect the Cosmopolitan theme is re-styling datagrid column headers with some kind of custom template, so that you can't just assign a string value to the Header property of DataGridTextColumns.

    Just another way Lightswitch shows some hate towards experienced Silverlight/WPF developers who thought they found a good RAD tool.  I know this is two years later (almost to the day), but did you ever find a workaround?

    Tuesday, July 14, 2015 6:59 PM