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. How to delete a row from a datagrid based upon a value from another in WPF

How to delete a row from a datagrid based upon a value from another in WPF

Scheduled Pinned Locked Moved WPF
csharpwpfarchitecturedesignregex
7 Posts 3 Posters 0 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.
  • U Offline
    U Offline
    User 2970611
    wrote on last edited by
    #1

    I am new to WPF, but I would like to know if someone can show me how to delete a row in one datagrid based upon a selection from another. The application uses C# and MVVM design pattern. Can anyone help? Thanks

    A M 2 Replies Last reply
    0
    • U User 2970611

      I am new to WPF, but I would like to know if someone can show me how to delete a row in one datagrid based upon a selection from another. The application uses C# and MVVM design pattern. Can anyone help? Thanks

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      If your DataGrid utilizes the SelectedItem property as follows

      , you can get the selected row. Based on the columns in it, you can pick up the id and delete from the other grid.

      The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

      U 1 Reply Last reply
      0
      • U User 2970611

        I am new to WPF, but I would like to know if someone can show me how to delete a row in one datagrid based upon a selection from another. The application uses C# and MVVM design pattern. Can anyone help? Thanks

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

        I would use linq to identify the record to be deleted and then remove it from the list

        classname Instance = Listname.Where(x=>x.Field = Criteria).FirstOrDefault();
        if(Instance !=Null)
        {ListName.Remove(Instance);}

        Never underestimate the power of human stupidity RAH

        U 1 Reply Last reply
        0
        • A Abhinav S

          If your DataGrid utilizes the SelectedItem property as follows

          , you can get the selected row. Based on the columns in it, you can pick up the id and delete from the other grid.

          The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

          U Offline
          U Offline
          User 2970611
          wrote on last edited by
          #4

          How would this work in MVVM? As the application has been built using this design pattern.

          A 1 Reply Last reply
          0
          • M Mycroft Holmes

            I would use linq to identify the record to be deleted and then remove it from the list

            classname Instance = Listname.Where(x=>x.Field = Criteria).FirstOrDefault();
            if(Instance !=Null)
            {ListName.Remove(Instance);}

            Never underestimate the power of human stupidity RAH

            U Offline
            U Offline
            User 2970611
            wrote on last edited by
            #5

            How would this work in MVVM? As the application has been built using this design pattern.

            M 1 Reply Last reply
            0
            • U User 2970611

              How would this work in MVVM? As the application has been built using this design pattern.

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

              Member 2972992 wrote:

              As the application has been built using this design pattern

              This indicates it was not built by you and it seem you have limited exposure to MVVM or Silverlight. It is going to be a little difficult to explain in a forum post, you have a learning curve in front of you that is going to include at least 1 book!

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              • U User 2970611

                How would this work in MVVM? As the application has been built using this design pattern.

                A Offline
                A Offline
                Abhinav S
                wrote on last edited by
                #7

                The view model should be bound to the datacontext, so the SelectedItem property should get it.

                The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

                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