Click here to Skip to main content
15,878,748 members
Home / Discussions / WPF
   

WPF

 
AnswerWPF ListBoxView Problem Pin
Alisaunder23-May-19 2:17
Alisaunder23-May-19 2:17 
AnswerRe: WPF ListBoxView Problem Pin
Gerry Schmitz23-May-19 3:31
mveGerry Schmitz23-May-19 3:31 
AnswerRe: WPF ListBoxView Problem Pin
Alisaunder23-May-19 7:19
Alisaunder23-May-19 7:19 
GeneralRe: WPF ListBoxView Problem Pin
Gerry Schmitz23-May-19 7:44
mveGerry Schmitz23-May-19 7:44 
QuestionWPF Geometry Question Pin
Kevin Marois9-May-19 9:56
professionalKevin Marois9-May-19 9:56 
AnswerRe: WPF Geometry Question Pin
Richard Deeming9-May-19 10:14
mveRichard Deeming9-May-19 10:14 
GeneralRe: WPF Geometry Question Pin
Kevin Marois9-May-19 10:25
professionalKevin Marois9-May-19 10:25 
QuestionDataGrid Binding Problem Pin
Kevin Marois29-Apr-19 17:37
professionalKevin Marois29-Apr-19 17:37 
I'm trying to get a simple datagrid to work. I've been Googling and searching and can't figure this out.

Entity
public class PurchaseOrderEntity : _EntityBase
{
    private int _Quantity;
    public int Quantity
    {
        get { return _Quantity; }
        set
        {
            if (_Quantity != value)
            {
                _Quantity = value;
                RaisePropertyChanged("Quantity");
            }
        }
    }

    private int _SizeId;
    public int SizeId
    {
        get { return _SizeId; }
        set
        {
            if (_SizeId != value)
            {
                _SizeId = value;
                RaisePropertyChanged("SizeId");
            }
        }
    }

}
View Model
private List<PurchaseOrderEntity> _PurchaseOrders;
public List<PurchaseOrderEntity> PurchaseOrders
{
    get { return _PurchaseOrders; }
    set
    {
        if (_PurchaseOrders != value)
        {
            _PurchaseOrders = value;
            RaisePropertyChanged("PurchaseOrders");
        }
    }
}

private PurchaseOrderEntity _SelectedPurchaseOrder;
public PurchaseOrderEntity SelectedPurchaseOrder
{
    get { return _SelectedPurchaseOrder; }
    set
    {
        if (_SelectedPurchaseOrder != value)
        {
            _SelectedPurchaseOrder = value;
            RaisePropertyChanged("SelectedPurchaseOrder");
        }
    }
}
DataGrid
<DataGrid Grid.Row="2"
            Margin="5"
            x:Name="lumberGrid"
            ItemsSource="{Binding PurchaseOrders}"
            SelectedItem="{Binding SelectedPurchaseOrder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            HorizontalGridLinesBrush="LightGray"
            VerticalGridLinesBrush="LightGray"
            AutoGenerateColumns="False"
            CanUserAddRows="True"
            CanUserDeleteRows="True"
            CanUserReorderColumns="False"
            CanUserResizeColumns="False"
            CanUserSortColumns="False"
            BorderBrush="SteelBlue"
            BorderThickness="1"
            HorizontalScrollBarVisibility="Auto"
            VerticalScrollBarVisibility="Auto"
            VerticalAlignment="Stretch">

<pre>
<DataGrid.Columns>

    <DataGridTextColumn Header="Quantity" 
                        Binding="{Binding Quantity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        Width="85"/>

    <DataGridTemplateColumn Header="Size"
                            Width="85">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ComboBox ItemsSource="{Binding Path=DataContext.LumberSizes, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                            DisplayMemberPath="Caption"
                            SelectedValuePath="Id"
                            SelectedValue="{Binding SizeId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>

</DataGrid.Columns>



When I run the code, then click on the new row, a red border apprears around the datagrid, and the output window shows this message:
System.Windows.Data Error: 23 : Cannot convert '{NewItemPlaceholder}' from type 'NamedObject' to type 'Jayhawk.Entities.PurchaseOrderEntity' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: TypeConverter cannot convert from MS.Internal.NamedObject.
   at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
   at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'

   System.Windows.Data Error: 7 : ConvertBack cannot convert value '{NewItemPlaceholder}' (type 'NamedObject'). BindingExpression:Path=SelectedPurchaseOrder; DataItem='AddEditPOViewModel' (HashCode=11892013); target element is 'DataGrid' (Name='lumberGrid'); target property is 'SelectedItem' (type 'Object') NotSupportedException:'System.NotSupportedException: TypeConverter cannot convert from MS.Internal.NamedObject.
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
   at MS.Internal.Data.ObjectTargetConverter.ConvertBack(Object o, Type type, Object parameter, CultureInfo culture)
   at System.Windows.Data.BindingExpression.ConvertBackHelper(IValueConverter converter, Object value, Type sourceType, Object parameter, CultureInfo culture)'

What am I doing wrong here??
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: DataGrid Binding Problem Pin
Gerry Schmitz29-Apr-19 18:22
mveGerry Schmitz29-Apr-19 18:22 
GeneralRe: DataGrid Binding Problem Pin
Kevin Marois30-Apr-19 4:34
professionalKevin Marois30-Apr-19 4:34 
GeneralRe: DataGrid Binding Problem Pin
Gerry Schmitz30-Apr-19 5:43
mveGerry Schmitz30-Apr-19 5:43 
GeneralRe: DataGrid Binding Problem Pin
Kevin Marois30-Apr-19 6:47
professionalKevin Marois30-Apr-19 6:47 
GeneralRe: DataGrid Binding Problem Pin
Gerry Schmitz30-Apr-19 21:46
mveGerry Schmitz30-Apr-19 21:46 
AnswerRe: DataGrid Binding Problem Pin
Mycroft Holmes29-Apr-19 21:19
professionalMycroft Holmes29-Apr-19 21:19 
GeneralRe: DataGrid Binding Problem Pin
Kevin Marois30-Apr-19 4:35
professionalKevin Marois30-Apr-19 4:35 
GeneralRe: DataGrid Binding Problem Pin
Mycroft Holmes30-Apr-19 12:25
professionalMycroft Holmes30-Apr-19 12:25 
AnswerRe: DataGrid Binding Problem Pin
Richard Deeming1-May-19 8:32
mveRichard Deeming1-May-19 8:32 
QuestionBinding "SelectedItems" of a Listbox Pin
Jayme6524-Mar-19 1:15
Jayme6524-Mar-19 1:15 
AnswerRe: Binding "SelectedItems" of a Listbox Pin
Gerry Schmitz24-Mar-19 6:15
mveGerry Schmitz24-Mar-19 6:15 
QuestionMicrosoft Documentation Pin
RichardChiles8-Mar-19 12:41
RichardChiles8-Mar-19 12:41 
AnswerRe: Microsoft Documentation Pin
Richard Deeming8-Mar-19 13:35
mveRichard Deeming8-Mar-19 13:35 
GeneralRe: Microsoft Documentation Pin
RichardChiles8-Mar-19 13:46
RichardChiles8-Mar-19 13:46 
GeneralRe: Microsoft Documentation Pin
Richard Deeming11-Mar-19 9:03
mveRichard Deeming11-Mar-19 9:03 
QuestionPlot LineSeries with out point Markers. Pin
RichardChiles8-Mar-19 12:39
RichardChiles8-Mar-19 12:39 
Questiondynamic tabitems with dynamic buttons in each tabitem Pin
siebren beens4-Mar-19 1:47
siebren beens4-Mar-19 1:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.