Click here to Skip to main content
14,696,502 members
Home » Discussions » Silverlight / WPF
   

Silverlight / WPF

 
AnswerWPF ListBoxView Problem Pin
Alisaunder23-May-19 3:17
MemberAlisaunder23-May-19 3:17 
AnswerRe: WPF ListBoxView Problem Pin
Gerry Schmitz23-May-19 4:31
mveGerry Schmitz23-May-19 4:31 
AnswerRe: WPF ListBoxView Problem Pin
Alisaunder23-May-19 8:19
MemberAlisaunder23-May-19 8:19 
GeneralRe: WPF ListBoxView Problem Pin
Gerry Schmitz23-May-19 8:44
mveGerry Schmitz23-May-19 8:44 
QuestionWPF Geometry Question Pin
Kevin Marois9-May-19 10:56
professionalKevin Marois9-May-19 10:56 
AnswerRe: WPF Geometry Question Pin
Richard Deeming9-May-19 11:14
mveRichard Deeming9-May-19 11:14 
GeneralRe: WPF Geometry Question Pin
Kevin Marois9-May-19 11:25
professionalKevin Marois9-May-19 11:25 
QuestionDataGrid Binding Problem Pin
Kevin Marois29-Apr-19 18:37
professionalKevin Marois29-Apr-19 18: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 19:22
mveGerry Schmitz29-Apr-19 19:22 
GeneralRe: DataGrid Binding Problem Pin
Kevin Marois30-Apr-19 5:34
professionalKevin Marois30-Apr-19 5:34 
GeneralRe: DataGrid Binding Problem Pin
Gerry Schmitz30-Apr-19 6:43
mveGerry Schmitz30-Apr-19 6:43 
GeneralRe: DataGrid Binding Problem Pin
Kevin Marois30-Apr-19 7:47
professionalKevin Marois30-Apr-19 7:47 
GeneralRe: DataGrid Binding Problem Pin
Gerry Schmitz30-Apr-19 22:46
mveGerry Schmitz30-Apr-19 22:46 
AnswerRe: DataGrid Binding Problem Pin
Mycroft Holmes29-Apr-19 22:19
professionalMycroft Holmes29-Apr-19 22:19 
GeneralRe: DataGrid Binding Problem Pin
Kevin Marois30-Apr-19 5:35
professionalKevin Marois30-Apr-19 5:35 
GeneralRe: DataGrid Binding Problem Pin
Mycroft Holmes30-Apr-19 13:25
professionalMycroft Holmes30-Apr-19 13:25 
AnswerRe: DataGrid Binding Problem Pin
Richard Deeming1-May-19 9:32
mveRichard Deeming1-May-19 9:32 
QuestionBinding "SelectedItems" of a Listbox Pin
Jayme6524-Mar-19 2:15
MemberJayme6524-Mar-19 2:15 
AnswerRe: Binding "SelectedItems" of a Listbox Pin
Gerry Schmitz24-Mar-19 7:15
mveGerry Schmitz24-Mar-19 7:15 
QuestionMicrosoft Documentation Pin
RichardChiles8-Mar-19 13:41
MemberRichardChiles8-Mar-19 13:41 
AnswerRe: Microsoft Documentation Pin
Richard Deeming8-Mar-19 14:35
mveRichard Deeming8-Mar-19 14:35 
GeneralRe: Microsoft Documentation Pin
RichardChiles8-Mar-19 14:46
MemberRichardChiles8-Mar-19 14:46 
GeneralRe: Microsoft Documentation Pin
Richard Deeming11-Mar-19 10:03
mveRichard Deeming11-Mar-19 10:03 
QuestionPlot LineSeries with out point Markers. Pin
RichardChiles8-Mar-19 13:39
MemberRichardChiles8-Mar-19 13:39 
Questiondynamic tabitems with dynamic buttons in each tabitem Pin
siebren beens4-Mar-19 2:47
Membersiebren beens4-Mar-19 2: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.