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. Other Discussions
  3. The Weird and The Wonderful
  4. When the comment is longer than the code

When the comment is longer than the code

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdatabaselinqalgorithmslearning
7 Posts 6 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.
  • OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #1

    Five or six times longer...

    /// <summary>
    /// Gets and sets the selected indexes
    /// </summary>
    /// <remarks>
    /// This is necessarily complicated.
    /// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
    /// was derived) and the outside world expects indexes to to relative to that DT.
    /// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
    /// filtering and sorting to the DV according to the user input.
    /// So the selected rows we get from the DGV are in last-selected-by-user order, (which
    /// if fine and dandy), but are relative to the DGV rather than the underlying DV or
    /// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
    ///
    /// So, we get the selected items from the DGV (only place we can, the DV doesn't know
    /// about selection), then have to convert that to the DataRow and get the index of that
    /// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
    /// annoying...
    /// And that's just Get!
    /// </remarks>
    [Browsable(false),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public IEnumerable<int> SelectedIndexes
    {
    get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
    set { ... }
    }

    I almost wish I'd written it longhand instead of using Linq methods... :laugh:

    Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    M D K 3 Replies Last reply
    0
    • OriginalGriffO OriginalGriff

      Five or six times longer...

      /// <summary>
      /// Gets and sets the selected indexes
      /// </summary>
      /// <remarks>
      /// This is necessarily complicated.
      /// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
      /// was derived) and the outside world expects indexes to to relative to that DT.
      /// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
      /// filtering and sorting to the DV according to the user input.
      /// So the selected rows we get from the DGV are in last-selected-by-user order, (which
      /// if fine and dandy), but are relative to the DGV rather than the underlying DV or
      /// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
      ///
      /// So, we get the selected items from the DGV (only place we can, the DV doesn't know
      /// about selection), then have to convert that to the DataRow and get the index of that
      /// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
      /// annoying...
      /// And that's just Get!
      /// </remarks>
      [Browsable(false),
      DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      public IEnumerable<int> SelectedIndexes
      {
      get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
      set { ... }
      }

      I almost wish I'd written it longhand instead of using Linq methods... :laugh:

      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

      M Offline
      M Offline
      mcep5f2009
      wrote on last edited by
      #2

      You just made my day lol

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Five or six times longer...

        /// <summary>
        /// Gets and sets the selected indexes
        /// </summary>
        /// <remarks>
        /// This is necessarily complicated.
        /// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
        /// was derived) and the outside world expects indexes to to relative to that DT.
        /// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
        /// filtering and sorting to the DV according to the user input.
        /// So the selected rows we get from the DGV are in last-selected-by-user order, (which
        /// if fine and dandy), but are relative to the DGV rather than the underlying DV or
        /// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
        ///
        /// So, we get the selected items from the DGV (only place we can, the DV doesn't know
        /// about selection), then have to convert that to the DataRow and get the index of that
        /// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
        /// annoying...
        /// And that's just Get!
        /// </remarks>
        [Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public IEnumerable<int> SelectedIndexes
        {
        get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
        set { ... }
        }

        I almost wish I'd written it longhand instead of using Linq methods... :laugh:

        Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Fantastic! I thought I was the only one who wrote comments like that. I feel so much relief! Thanks Griff.

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        OriginalGriffO M 2 Replies Last reply
        0
        • D Dave Kreskowiak

          Fantastic! I thought I was the only one who wrote comments like that. I feel so much relief! Thanks Griff.

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          I just know that in a years time I'm going to look at that line of code and go "What? Why?" :laugh: Perhaps I can head myself off at the pass!

          Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          S 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            I just know that in a years time I'm going to look at that line of code and go "What? Why?" :laugh: Perhaps I can head myself off at the pass!

            Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

            S Offline
            S Offline
            Swinkaran
            wrote on last edited by
            #5

            Sometimes it is easy to understand by looking at the code rather than the comment. There are such programmers.

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Five or six times longer...

              /// <summary>
              /// Gets and sets the selected indexes
              /// </summary>
              /// <remarks>
              /// This is necessarily complicated.
              /// Remember, the data comes from a DataTable (DT) - (or a list from which the DT data
              /// was derived) and the outside world expects indexes to to relative to that DT.
              /// But...we display the data in a DataGridView (DGV) via a DataView (DV) and apply
              /// filtering and sorting to the DV according to the user input.
              /// So the selected rows we get from the DGV are in last-selected-by-user order, (which
              /// if fine and dandy), but are relative to the DGV rather than the underlying DV or
              /// DT data source, as the DGV is subject to the sorting and filtering applied to the DV.
              ///
              /// So, we get the selected items from the DGV (only place we can, the DV doesn't know
              /// about selection), then have to convert that to the DataRow and get the index of that
              /// from the DT. But (of course) the DGV returns a DataGridViewRow object just to be
              /// annoying...
              /// And that's just Get!
              /// </remarks>
              [Browsable(false),
              DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
              public IEnumerable<int> SelectedIndexes
              {
              get { return dgvData.SelectedRows.Cast<DataGridViewRow>().Select(r => _DataSource.Rows.IndexOf(((DataRowView)r.DataBoundItem).Row)); }
              set { ... }
              }

              I almost wish I'd written it longhand instead of using Linq methods... :laugh:

              Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

              K Offline
              K Offline
              Karen Mitchelle
              wrote on last edited by
              #6

              That's fine. Documentations are always longer than codes. :laugh:

              Don't mind those people who say you're not HOT. At least you know you're COOL. I'm not afraid of falling, I'm afraid of the sudden stop at the end of the fall! - Richard Andrew x64

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                Fantastic! I thought I was the only one who wrote comments like that. I feel so much relief! Thanks Griff.

                A guide to posting questions on CodeProject

                Click this: Asking questions is a skill. Seriously, do it.
                Dave Kreskowiak

                M Offline
                M Offline
                MarkTJohnson
                wrote on last edited by
                #7

                I write comments like that too, especially if I have to do something that isn't obvious as to WHY I'm doing it. (Usually because the client is asking for something that's just the opposite of what they wanted six months ago.) It also lets other people know to think twice before changing that code willy-nilly.

                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