Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. DataGrid Binding Problem

DataGrid Binding Problem

Scheduled Pinned Locked Moved WPF
wpfwcfalgorithmshelp
10 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    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

    L M Richard DeemingR 3 Replies Last reply
    0
    • K Kevin Marois

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • K Kevin Marois

        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

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        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

        K 1 Reply Last reply
        0
        • L Lost User

          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

          K Offline
          K Offline
          Kevin Marois
          wrote on last edited by
          #4

          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.

          L 1 Reply Last reply
          0
          • M Mycroft Holmes

            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

            K Offline
            K Offline
            Kevin Marois
            wrote on last edited by
            #5

            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.

            M 1 Reply Last reply
            0
            • K Kevin Marois

              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.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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

              K 1 Reply Last reply
              0
              • L Lost User

                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

                K Offline
                K Offline
                Kevin Marois
                wrote on last edited by
                #7

                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.

                L 1 Reply Last reply
                0
                • K Kevin Marois

                  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.

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • K Kevin Marois

                    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.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • K Kevin Marois

                      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

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #10

                      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

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups