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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Sortable gridview with comboboxes and can add/delete rows [modified]

Sortable gridview with comboboxes and can add/delete rows [modified]

Scheduled Pinned Locked Moved C#
cssdatabasehelpquestion
6 Posts 2 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.
  • N Offline
    N Offline
    Nigel Mackay
    wrote on last edited by
    #1

    I need a pointer to an article that can help me with gridviews that are sortable, users can add and delete rows, and some of the columns are dropdowns referencing various datasets. The question is too complicated to Google or Search And not even one of my 23 books handles that situation. the values of e.RowIndex and e.Row.Index are no longer useful unless the table you use for the dropdown also gets sorted when you sort the gridview, or you use some sort of double-value table so you have a cross-reference to the correct row in the grid's dataset. I have considered using a struct or a dictionary for the dropdown's table, and then catching the Sort event to sort the struct/dictionary. Or updating the sort of the struct/dictionary on Paint, but maybe there is a better way. One of my grids consists only of 8 dropdowns, each pointing to a different dataset. Thanks.

    modified on Wednesday, September 2, 2009 2:08 AM

    M 1 Reply Last reply
    0
    • N Nigel Mackay

      I need a pointer to an article that can help me with gridviews that are sortable, users can add and delete rows, and some of the columns are dropdowns referencing various datasets. The question is too complicated to Google or Search And not even one of my 23 books handles that situation. the values of e.RowIndex and e.Row.Index are no longer useful unless the table you use for the dropdown also gets sorted when you sort the gridview, or you use some sort of double-value table so you have a cross-reference to the correct row in the grid's dataset. I have considered using a struct or a dictionary for the dropdown's table, and then catching the Sort event to sort the struct/dictionary. Or updating the sort of the struct/dictionary on Paint, but maybe there is a better way. One of my grids consists only of 8 dropdowns, each pointing to a different dataset. Thanks.

      modified on Wednesday, September 2, 2009 2:08 AM

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

      Are you using a GridView or a DataGridView (win or web). This article helped me with a DGV [^]

      N 1 Reply Last reply
      0
      • M Mycroft Holmes

        Are you using a GridView or a DataGridView (win or web). This article helped me with a DGV [^]

        N Offline
        N Offline
        Nigel Mackay
        wrote on last edited by
        #3

        I am using a DataGridViews on Windows forms. Had a look at the article, but it does not handle my problem: sortable, with comboboxes, and adding/deleting rows. Essentially, the question: which is the best way to handle the list of values that must be displayed in the combobox column - use a dictionary or a struct and sort the dictionary/struct when the grid is sorted, or maybe some other method. I started off using an ArrayList of int, but then I have no reference to sort it to the same order as the grid. So it has to be an ArrayList of a struct that stores the value that must go in the combobox and a value from some other column in the grid so that I can sort the ArrayList to the same order. And it starting to boggle my mind!

        M 1 Reply Last reply
        0
        • N Nigel Mackay

          I am using a DataGridViews on Windows forms. Had a look at the article, but it does not handle my problem: sortable, with comboboxes, and adding/deleting rows. Essentially, the question: which is the best way to handle the list of values that must be displayed in the combobox column - use a dictionary or a struct and sort the dictionary/struct when the grid is sorted, or maybe some other method. I started off using an ArrayList of int, but then I have no reference to sort it to the same order as the grid. So it has to be an ArrayList of a struct that stores the value that must go in the combobox and a value from some other column in the grid so that I can sort the ArrayList to the same order. And it starting to boggle my mind!

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

          Nigel Mackay wrote:

          And it starting to boggle my mind!

          I have only once EVER used a combo in a DGV, I'm of the school that says you do not edit data in a list control, I allow this to vary only on the most trivial operations so sorting a DGV with a combo in it is (and will stay) outside my scope. If your underlying data is a datatable/view then sorting should not be an issue if you bind to the text rather than the ID. Then how do you deal with the 'I sote the ID' problem.

          N 1 Reply Last reply
          0
          • M Mycroft Holmes

            Nigel Mackay wrote:

            And it starting to boggle my mind!

            I have only once EVER used a combo in a DGV, I'm of the school that says you do not edit data in a list control, I allow this to vary only on the most trivial operations so sorting a DGV with a combo in it is (and will stay) outside my scope. If your underlying data is a datatable/view then sorting should not be an issue if you bind to the text rather than the ID. Then how do you deal with the 'I sote the ID' problem.

            N Offline
            N Offline
            Nigel Mackay
            wrote on last edited by
            #5

            Not making the data in the gridview editable could very well be the the answer to my problem. Use the grid, sortable, for viewing and for finding the row to edit, and then using Add, Delete and Edit buttons to open dedicated forms for the three tasks. The row number doesn't have to used per se, a suitable value can be extracted from the grid in order to decide which record to Edit. And I still have the row number to put the edited values back into the grid. Deleting just needs confirmation. Adding can gather the data and then insert a row into the grid programatically. Will go that route - it just means creating a few more forms - 6 to be exact. Maybe the problems associated with what I was trying to do explains why I can find no info about it. :)

            M 1 Reply Last reply
            0
            • N Nigel Mackay

              Not making the data in the gridview editable could very well be the the answer to my problem. Use the grid, sortable, for viewing and for finding the row to edit, and then using Add, Delete and Edit buttons to open dedicated forms for the three tasks. The row number doesn't have to used per se, a suitable value can be extracted from the grid in order to decide which record to Edit. And I still have the row number to put the edited values back into the grid. Deleting just needs confirmation. Adding can gather the data and then insert a row into the grid programatically. Will go that route - it just means creating a few more forms - 6 to be exact. Maybe the problems associated with what I was trying to do explains why I can find no info about it. :)

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

              Nigel Mackay wrote:

              6 to be exact

              Meh - I've got hundreds of the bloody things for editing.... I put the id value I want into column[0] and set visible to false - I then know exactly where to find my edit id. I have also been known to chuck the datarow into the tag property if I am manually loading the DGV (I consider this cheating but it does make locating the record simple) I use doubleclick on the cell/row to initiate the edit operation and also have a toolstrip with AED buttons.

              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