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. C#
  4. DataView Column Order

DataView Column Order

Scheduled Pinned Locked Moved C#
helpcssquestion
5 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.
  • P Offline
    P Offline
    Pualee
    wrote on last edited by
    #1

    Hi, I am having an issue setting the column order on a grid: I created a DataTable with some bound and some un-bound columns. I created a DataGridView using the DataTable for input. I set the .DisplayIndex for all the DataGridView columns I then created a DataView using the DataGridView.DataSource I assigned the DataGridView.DataSource to the DataView. My columns to not appear in the correct order when first displayed, however, if I change the row filter on the DataView by responding to a GUI event, everything updates and my columns are in order. Also, another table using only bound columns displays correctly the first time. Has anyone had a similar issue or want to take a crack at this problem? Thanks in advance, Pualee

    J 1 Reply Last reply
    0
    • P Pualee

      Hi, I am having an issue setting the column order on a grid: I created a DataTable with some bound and some un-bound columns. I created a DataGridView using the DataTable for input. I set the .DisplayIndex for all the DataGridView columns I then created a DataView using the DataGridView.DataSource I assigned the DataGridView.DataSource to the DataView. My columns to not appear in the correct order when first displayed, however, if I change the row filter on the DataView by responding to a GUI event, everything updates and my columns are in order. Also, another table using only bound columns displays correctly the first time. Has anyone had a similar issue or want to take a crack at this problem? Thanks in advance, Pualee

      J Offline
      J Offline
      joon vh
      wrote on last edited by
      #2

      You can change column order by setting the DisplayIndex property. Take in mind that no 2 columns can have the same index. If the data is not very likely to change, you could manually add the columns in the datagridview via the IDE, and turn off autogeneratecolumns.


      Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

      P 2 Replies Last reply
      0
      • J joon vh

        You can change column order by setting the DisplayIndex property. Take in mind that no 2 columns can have the same index. If the data is not very likely to change, you could manually add the columns in the datagridview via the IDE, and turn off autogeneratecolumns.


        Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

        P Offline
        P Offline
        Pualee
        wrote on last edited by
        #3

        I set display index as follows: Int32 i; i = 0; dgvItem.Columns["X"].DisplayIndex = i++; dgvItem.Columns["Y"].DisplayIndex = i++; dgvItem.Columns["Z"].DisplayIndex = i++; So I know I'm not duplicating indexes. I think autogeneratecolumns could get me in trouble (not sure) as I am constantly resetting the filter on the DataView and then resetting the DataGridView.DataSource = DataView. I do not know if this operation would clear and re-add the columns or not. I kind of expect it would since the columns come up wrong, but then correct themselves after changing the DataView filter the first time.

        1 Reply Last reply
        0
        • J joon vh

          You can change column order by setting the DisplayIndex property. Take in mind that no 2 columns can have the same index. If the data is not very likely to change, you could manually add the columns in the datagridview via the IDE, and turn off autogeneratecolumns.


          Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

          P Offline
          P Offline
          Pualee
          wrote on last edited by
          #4

          On second thought, I think you are right. I have been trying to figure out how to eliminate the necessity of resetting all my column properties each time I update the filter. The columns will never change, just the records. If I manually add the columns and disable the autogeneratecolumns, I suspect I will only have to set the properties once and save a little bit of overhead when changing the records displayed... Thanks!

          J 1 Reply Last reply
          0
          • P Pualee

            On second thought, I think you are right. I have been trying to figure out how to eliminate the necessity of resetting all my column properties each time I update the filter. The columns will never change, just the records. If I manually add the columns and disable the autogeneratecolumns, I suspect I will only have to set the properties once and save a little bit of overhead when changing the records displayed... Thanks!

            J Offline
            J Offline
            joon vh
            wrote on last edited by
            #5

            Your welcome. Sometimes the IDE holds the key ;) there are some other shortcuts you can take this way like making checkboxcolumns and the likes.


            Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

            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