Home Forums WPF controls Xceed DataGrid for WPF Can’t get a simple SQL databind to work

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25565 |

    I have read through the sample documentation and modeled this little test page after the code. I tested the SQL in the query analyzer and I know that is working. I am using Visual Studio 2008 Professional to try and make this work. It just comes up empty everytime with an option to “Drag a column header here to group by that column”. I really need to use a datagrid in WPF. Any help would be greatly appreciated. Thanks, Michael

    Here is the XAML

    <Page x:Class=”Page1″
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    Title=”Page1″ Width=”929″ Height=”398″ xmlns:xcdg=”clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid”>
    <Page.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvsTTEPhoneJobs” Source=”{Binding Source={x:Static Application.Current}, Path=Jobs}”></xcdg:DataGridCollectionViewSource>
    </Page.Resources>
    <Grid>
    <xcdg:DataGridControl Name=”DataGridControl1″ ItemsSource=”{Binding Source={StaticResource cvsTTEPhoneJobs}}” VerticalAlignment=”Top”>
    </xcdg:DataGridControl>
    </Grid>
    </Page>

    Here is the code behind.

    Imports System.Data.OleDb
    Imports System.Data
    Imports System.Data.SqlClient
    Partial Public Class Admins
    Private Shared getPhoneData As DataTable
    Shared Sub New()
    Dim ds As New DataSet()
    Dim adapter As New SqlDataAdapter()
    Dim connString As New SqlConnection(“Data Source=(local);Initial Catalog=TTEPhone;Integrated Security=True”)
    adapter.SelectCommand = New SqlCommand(“SELECT DictatorID, ConfirmationID, JobStart FROM Jobs”, connString)
    adapter.Fill(ds, “Jobs”)
    getPhoneData = ds.Tables(“Jobs”)
    End Sub

    Public Shared ReadOnly Property Jobs() As DataTable
    Get
    Return getPhoneData
    End Get
    End Property
    End Class

    Imported from legacy forums. Posted by Michael (had 3860 views)

    Xceed Support
    Member
    Post count: 5658

    Are there any errors in the output window? Also, your current code is looking for the Jobs property in the App.xaml.cs. Is this were the property is located?

    Imported from legacy forums. Posted by Jenny [Xceed] (had 181 views)

    User (Old forums)
    Member
    Post count: 23064

    I see this error.
    System.Windows.Data Error: 35 : BindingExpression path error: ‘Jobs’ property not found on ‘object’ ”Application’ (HashCode=3741682)’. BindingExpression:Path=Jobs; DataItem=’Application’ (HashCode=3741682); target element is ‘DataGridCollectionViewSource’ (HashCode=33675143); target property is ‘Source’ (type ‘Object’)

    I don’t understand how it’s pointint to Application.xaml.vb. The name of my XAML page is simply Page1.xaml(just trying to see if this is going to work) and the code behind is Page1.xaml.vb. How do I need to modify my code. Thanks, Michael

    Imported from legacy forums. Posted by Michael (had 270 views)

    Xceed Support
    Member
    Post count: 5658

    Change your binding in the DataGridCollectionViewSource to point to the main page rather than the Application.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 175 views)

    User (Old forums)
    Member
    Post count: 23064

    I am guessing you are referring to x:Static Application.Current

    I changed it to x:Static Page1.Current and I receive the following error;

    Could not create an instance of type ‘StaticExtension’.

    Not quite sure what to do from here, but I appreciating you helping me work this through. Thanks, Michael

    Imported from legacy forums. Posted by Michael (had 252 views)

    Xceed Support
    Member
    Post count: 5658

    If both the DataGridCollectionViewSource and the Page where your property is are in the same data context, then {Binding Path=Jobs} should work.

    If not, you will need to do a RelativeSource binding: {Binding RelativeSource={RelativeSource AncestorType={x:Type Page1}}, Path=Jobs}

    Disclaimer: I am at home and have typed the bindings off the top of my head, you may need to do some tweaking to fit it to your exact scenario.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 4983 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.