Home Forums WPF controls Xceed DataGrid for WPF Help binding to a DataTable

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

    Trying to make THIS work.. nothing else has… using the example provided, I have a small test app:

    <Window x:Class=”XTest.Window1″
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    Title=”Window1″ Height=”599″ Width=”781″ xmlns:xcdg=”clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid” xmlns:xcdg1=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
    <Grid Background=”IndianRed”>
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource
    x:Key=”cvs_data”
    Source=”{Binding Source={x:Static Application.Current},
    Path=Data}”/>
    </Grid.Resources>
    <xcdg:DataGridControl Margin=”18,17,16,61″
    AutoCreateColumns=”True”
    Name=”dataGridControl1″
    ItemsSource=”{Binding Source={StaticResource cvs_data}}”>
    <xcdg:DataGridControl.View>
    <xcdg1:TableView ShowFixedColumnSplitter=”False”>
    <xcdg1:TableView.Theme>
    <xcdg1:AeroNormalColorTheme />
    </xcdg1:TableView.Theme>
    </xcdg1:TableView>
    </xcdg:DataGridControl.View>
    </xcdg:DataGridControl>
    </Grid>
    </Window>

    and here’s the codebehind:

    namespace XTest
    {
    /// <summary>
    /// Interaction logic for Window1.xamlG
    /// </summary>
    public partial class Window1 : Window
    {
    private static DataTable m_data;

    public Window1()
    {

    MSTSSchedule schedToday;
    int hoursToAdd = 48;

    List<String> scope = GetContainers();

    // define a Query
    MSTSVQuery qry = new MSTSVQuery();
    qry.MatchAll = true; // very important to set this to TRUE!
    DateTime today = DateTime.Now;
    DateTime start = new DateTime(today.Year, today.Month, today.Day, 00, 00, 00);
    DateTime end = start.AddHours(hoursToAdd – 1);
    qry.StartDate = start;
    qry.EndDate = end;

    // read the data
    schedToday = MSTSGlobalSchedule.GlobalReadSchedule(scope, qry);
    schedToday.Sort();

    m_data = schedToday.GetAsDataTable(); <== this works and using the debugger shows valid data

    InitializeComponent();

    }

    public static DataTable Data
    {
    get
    {
    return m_data;
    }
    }

    Still, as with all my attempts, zero rows. Nothing. Nada.

    Imported from legacy forums. Posted by yahgrid27 (had 4161 views)

    User (Old forums)
    Member
    Post count: 23064

    “{Binding Source={x:Static Application.Current}, Path=Data}”

    Data is not a Property of Application.Current so Path=Data will not work.

    This is a frustrating part of debugging in WPF no errors or intellisense help for bad bindings.

    Unfortunately Window1.Data doesn’t work either. I gave up on it and bind it in the code behind.

    The binding above becomes “{Binding}”

    and then in code behind I do this:

    InitializeComponent();
    DataContext = Data;

    (Actually currently I create the DataGridCollectionView in the codebehind and then I set the dataGridControl1.ItemsSource to that.)

    Hope that helps.

    John

    Imported from legacy forums. Posted by John (had 596 views)

    User (Old forums)
    Member
    Post count: 23064

    You’re the first person to really dig in and provide concrete help.

    I agree.. it’s so frustrating because as WPF is a declarative approach, you can’t “trace” it as you can the C# code behind.

    I understand the general push is to do as much in the XAML as possible, but it sure is easier to debug if the work is done in code… I use the debugger like my bible and wish similar functionality was available for the markup.

    thanks again!

    Imported from legacy forums. Posted by yahgrid27 (had 476 views)

    User (Old forums)
    Member
    Post count: 23064

    “I understand the general push is to do as much in the XAML as possible, but it sure is easier to debug if the work is done in code… I use the debugger like my bible and wish similar functionality was available for the markup. “

    I get that feeling too. But it’s wrong in my opinion.

    XAML = Designers Work
    Codebehind = Coders Work

    My view is you only want to put the stuff that is necessary for the designer to do his work in the XAML everything else should be in the codebehind.

    Imported from legacy forums. Posted by John (had 492 views)

    Odi [Xceed]
    Spectator
    Post count: 426

    >>You’re the first person to really dig in and provide concrete help.

    That’s probably because you posted your first message in this thread yesterday, which was a saturday 🙂 There’s a lot less activity on weekends.

    I might as well also mention that while Xceed developers and support staff often respond to messages here to help out the community, their priorities are development and supporting customers with paid support subscriptions respectively. When a particularly important release is being worked on that (like v2.1 of the DataGrid is), or the release date is imminent, our staff has less time to help out in the forums. On weekends, they definitely need a break, though!

    Imported from legacy forums. Posted by Odi [Xceed] (had 557 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes, I understand… and am grateful for the help that they provide.

    Imported from legacy forums. Posted by yahgrid27 (had 5311 views)

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