DataGrid Binding Problem
-
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 _PurchaseOrders;
public List 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
-
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 _PurchaseOrders;
public List 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
SelectedItem="{Binding SelectedPurchaseOrder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
99% of the population would use the selected item changed event handler. (and I would use a "form" for adding new records). (MVVM sucks again in this case)
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
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 _PurchaseOrders;
public List 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
I think your List<> in the viewmodel should be an ObservableCollection<> I would also test it without the combobox in the grid (I NEVER allow complex controls in a data grid).
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
SelectedItem="{Binding SelectedPurchaseOrder, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
99% of the population would use the selected item changed event handler. (and I would use a "form" for adding new records). (MVVM sucks again in this case)
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
This is a heads up data entry form. The user needs to be able to enter a lot of data quickly. Stopping to grab the mouse is not really what they're looking for.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
I think your List<> in the viewmodel should be an ObservableCollection<> I would also test it without the combobox in the grid (I NEVER allow complex controls in a data grid).
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
See my reply to Gerry
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
This is a heads up data entry form. The user needs to be able to enter a lot of data quickly. Stopping to grab the mouse is not really what they're looking for.
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
Quote:
Stopping to grab the mouse is not really what they're looking for.
[How to implement Hot Keys in WPF?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/0c9577dc-cf71-4631-bff9-c41ab6b0ea58/how-to-implement-hot-keys-in-wpf?forum=wpf) [Assigning Keyboard Shortcut / Access Keys to your WPF Application – Mohammed Jeelani's Blog](https://blogs.msdn.microsoft.com/mjeelani/2007/12/15/assigning-keyboard-shortcut-access-keys-to-your-wpf-application/) etc. (I though it was "heads-down")
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
Quote:
Stopping to grab the mouse is not really what they're looking for.
[How to implement Hot Keys in WPF?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/0c9577dc-cf71-4631-bff9-c41ab6b0ea58/how-to-implement-hot-keys-in-wpf?forum=wpf) [Assigning Keyboard Shortcut / Access Keys to your WPF Application – Mohammed Jeelani's Blog](https://blogs.msdn.microsoft.com/mjeelani/2007/12/15/assigning-keyboard-shortcut-access-keys-to-your-wpf-application/) etc. (I though it was "heads-down")
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
This feels like work arounds. I'll do an entry form is all else fails, but it has to be possible to do what I want. I've seen data entry grids before.
Gerry Schmitz wrote:
(I though it was "heads-down")
:) :)
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
See my reply to Gerry
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
But but a combobox is going to slow down data entry, an auto complete textbox might be better with some validation after they leave the control. I would try really hard to move the data entry to a panel instead of within the grid.
Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
This feels like work arounds. I'll do an entry form is all else fails, but it has to be possible to do what I want. I've seen data entry grids before.
Gerry Schmitz wrote:
(I though it was "heads-down")
:) :)
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
You can do data entry in a data grid. You just wind up writing a lot more code and it gets very difficult to extend as soon as the user comes up with something weird. And, you're always sitting "at the bottom" when adding a new record. Combine the two: e.g. CTRL+N: pops up the form for a new record. PF5: pops up a form for the current record in grid (edit) CTRL+D: delete the current record in grid. CTRL+S: Save the current form / record (keep form open if in "data entry mode") ESC: release the form. Extra credits: Navigate in form. (Keyboard preview key down and handled at the "form" / window / user control level)
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
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 _PurchaseOrders;
public List 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
Looks like it's a known bug that dates back to 2009: Problems binding to SelectedValue with Microsoft’s WPF DataGrid | Nigel Spencer's Blog[^] c# - Bug in WPF DataGrid - Stack Overflow[^] The workaround seems to be to use a custom converter on the
SelectedItem
binding.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer