Home Forums WPF controls Xceed DataGrid for WPF Adding Combobox that is binded to a DataTable exception

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #23902 |

    I copied from the databinding sample the code for the supplierId binding and changed the binding to my specific data table that is a resource in my window.

    When the mouse is over the column I get an NullReferenceException.

    what did I do wrong?

    here is my code:
    <ObjectDataProvider x:Key=”genderDS” ObjectType=”{x:Type dataobj:GenderDataSet}” >

    <xcdg:CellEditor x:Key=”GenderEditor”>
    <ComboBox BorderThickness=”0″
    Foreground=”{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(TextElement.Foreground), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}”
    ItemsSource=”{Binding Source={StaticResource genderDS}, Path=PatientsGenders}”
    ItemTemplate=”{StaticResource genderDataTemplate}”
    SelectedValue=”{xcdg:CellEditorBinding }”>
    <Style TargetType=”Popup”>
    <Setter Property=”TextElement.Foreground”
    Value=”{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}” />
    <xcdg:KeyActivationGesture SystemKey=”Down”
    <xcdg:KeyActivationGesture Key=”Up”
    <xcdg:KeyActivationGesture Key=”F4″/>
    <xcdg:KeyActivationGesture Key=”Space”/>

    <!–A data template that will be used to represent a supplier with its company name–>
    <DataTemplate x:Key=”genderDataTemplate”>
    <TextBlock Text=”{Binding GenderName}”
    TextTrimming=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextTrimming}”
    TextWrapping=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextWrapping}”/>
    <!–A cell content template that will be used to represent a SupplierID with its company name–>
    <DataTemplate x:Key=”genderCellDataTemplate”>
    <local:GenderIDDictionary Key=”{TemplateBinding Content}”
    ContentTemplate=”{StaticResource genderDataTemplate}”>


    Imported from legacy forums. Posted by joy (had 782 views)

    User (Old forums)
    Post count: 23064

    It looks like you’re using the ObjectDataProvider wrong

    Read up here: http://msdn2.microsoft.com/en-us/library/system.windows.data.objectdataprovider.aspx

    Check out the following except from page 588 of Apress’s
    “Pro WPF Windows Presentation Foundation in .NET 3.0” by Matthew MacDonald

    I love this book, it’s a great read:


    “Pro WPF Windows Presentation Foundation in .NET 3.0” p. 588 The ObjectDataProvider
    The ObjectDataProvider allows you to get information from another class in your application.
    It adds the following features:

    It can create the object you need and pass parameters to the constructor.

    It can call a method in that object and pass method parameters to it.

    It can create the data object asynchronously. (In other words, it can wait until after the
    window is loaded and then perform the work in the background.)

    For example, here’s a basic ObjectDataProvider that creates an instance of the StoreDB
    class, calls its GetProducts() method, and makes the data available to the rest of your window:

    <ObjectDataProvider x:Key=”productsProvider” ObjectType=”{x:Type local:StoreDB}”

    You can now create a binding that gets the source from the ObjectDataProvider:

    <ListBox Name=”lstProducts” DisplayMemberPath=”ModelName”
    ItemsSource=”{Binding Source={StaticResource productsProvider}}”></ListBox>

    This tag looks like it binds to the ObjectDataProvider, but the ObjectDataProvider is intelligent
    enough to know you really want to bind to the product list that it returns from the
    GetProducts() method.

    Imported from legacy forums. Posted by Richard (had 198 views)

    User (Old forums)
    Post count: 23064


    I should clarify…

    It looks like you “could be” using ObjectDataProvider wrong. I don’t actually know since I haven’t used it. But I was just comparing your code to some documentation.

    Perhaps the form you show works fine for a parameterless constructor. But I guess if you haven’t done so already, you’d want to confirm it does.


    Imported from legacy forums. Posted by Richard (had 351 views)

    User (Old forums)
    Post count: 23064

    hi Rich,

    Thanks you for your answer.

    I have tried that but It gave me a diffirent exception.
    the binding has failed.

    I do not think that there is a problem with the binding becuase the Patients is a property of the dataset and I see allthe items in the grid.
    When I debug the application I also see the items in the CellEditor.

    I think there is a problem to connect the cell value in the grid to the list of items in the cell editor but I do not know how to fix it.


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

    Xceed Support
    Post count: 5658


    Could you provide the exception’s stack trace as well as the DataGridControl’s xaml ( there is only the resources in the xaml you provided).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 4185 views)

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