DataGridView.CurrentCell (Set)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michel Walsh

    #1

    DataGridView.CurrentCell (Set)

    Someone has an example, C#, about how to set the cell(int row, int col) as
    the current cell for a DataGridView. The example, in the help file, about
    DataGrid.Curren tCell Property (Set)

    myGrid.CurrentC ell = new DataGridCell(1, 1);


    does not work, fro a DataGridView, since we cannot create a DataGridView
    Cell while specifying only its row and column.


    Vanderghast, Access MVP


  • Michel Walsh

    #2
    Re: DataGridView.Cu rrentCell (Set)

    Sorry for the bandwidth, just found that I just have to point to that said
    cell, after all... doh. No need to 'create' one, as the example from
    DataGrid leads us to think. The following works:


    dataGridView1.C urrentCell = dataGridView1.R ows[iRow].Cells[iCol];




    Vanderghast, Access MVP



    "Michel Walsh" <vanderghastAro baseMsnDotCom@n ospam.comwrote in message
    news:0D6B5380-AC27-4848-899F-E3FCBBB19E3E@mi crosoft.com...
    Someone has an example, C#, about how to set the cell(int row, int col)
    as the current cell for a DataGridView. The example, in the help file,
    about DataGrid.Curren tCell Property (Set)
    >
    myGrid.CurrentC ell = new DataGridCell(1, 1);
    >
    >
    does not work, fro a DataGridView, since we cannot create a DataGridView
    Cell while specifying only its row and column.
    >
    >
    Vanderghast, Access MVP
    >
    >

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: DataGridView.Cu rrentCell (Set)

      Michael,

      There are more succinct ways of doing this:

      dataGridView1.C urrentCellAddre ss = new Point(1, 1);

      Or, if you wish:

      dataGridView1.C urrentCell = dataGridView1[1, 1];

      Both should have the same effect, although the top example will help
      prevent unsharing of rows, which is good when you are using the grid in
      virtual mode.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Michel Walsh" <vanderghastAro baseMsnDotCom@n ospam.comwrote in message
      news:7F3E6D36-0AAE-4B15-B440-221798E799CF@mi crosoft.com...
      Sorry for the bandwidth, just found that I just have to point to that said
      cell, after all... doh. No need to 'create' one, as the example from
      DataGrid leads us to think. The following works:
      >
      >
      dataGridView1.C urrentCell = dataGridView1.R ows[iRow].Cells[iCol];
      >
      >
      >
      >
      Vanderghast, Access MVP
      >
      >
      >
      "Michel Walsh" <vanderghastAro baseMsnDotCom@n ospam.comwrote in message
      news:0D6B5380-AC27-4848-899F-E3FCBBB19E3E@mi crosoft.com...
      >Someone has an example, C#, about how to set the cell(int row, int col)
      >as the current cell for a DataGridView. The example, in the help file,
      >about DataGrid.Curren tCell Property (Set)
      >>
      >myGrid.Current Cell = new DataGridCell(1, 1);
      >>
      >>
      >does not work, fro a DataGridView, since we cannot create a DataGridView
      >Cell while specifying only its row and column.
      >>
      >>
      >Vanderghast, Access MVP
      >>
      >>
      >

      Comment

      • Michel Walsh

        #4
        Re: DataGridView.Cu rrentCell (Set)

        If I can ask you one more question.


        While

        dataGridView1.C urrentCell = dataGridView1[1, 1];

        is fine for me, if I consider dataGridView[1,1] is a reference (a pointer)
        to an existing cell, and then CurrentCell property just 'set the focus' on
        that 'object reference' it got as its 'value', I fail to see how:


        dataGridView1.C urrentCellAddre ss = new Point(1, 1);


        could even work, since

        new Point(1, 1)

        is also a reference, but totally unrelated to any cell-references
        (cell-pointers) owned by the dataGridView object. With this, in
        consideration, can you explain the inner-working of


        dataGridView1.C urrentCellAddre ss = new Point(1, 1);




        Thanks for your time
        Vanderghast, Access MVP



        "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
        message news:C3DF6C2C-724E-4B6A-8A17-C86C03A8F235@mi crosoft.com...
        Michael,
        >
        There are more succinct ways of doing this:
        >
        dataGridView1.C urrentCellAddre ss = new Point(1, 1);
        >
        Or, if you wish:
        >
        dataGridView1.C urrentCell = dataGridView1[1, 1];
        >
        Both should have the same effect, although the top example will help
        prevent unsharing of rows, which is good when you are using the grid in
        virtual mode.
        >
        >
        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m
        >

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: DataGridView.Cu rrentCell (Set)

          Michel,

          As you and Andrus pointed out, you the CurrentCellAddr ess property is
          read-only, so you can't set it.

          So only the first example I gave is valid.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Michel Walsh" <vanderghast@Vi rusAreFunnierTh anSpamwrote in message
          news:uSnFB29bIH A.5208@TK2MSFTN GP04.phx.gbl...
          If I can ask you one more question.
          >
          >
          While
          >
          dataGridView1.C urrentCell = dataGridView1[1, 1];
          >
          is fine for me, if I consider dataGridView[1,1] is a reference (a pointer)
          to an existing cell, and then CurrentCell property just 'set the focus' on
          that 'object reference' it got as its 'value', I fail to see how:
          >
          >
          dataGridView1.C urrentCellAddre ss = new Point(1, 1);
          >
          >
          could even work, since
          >
          new Point(1, 1)
          >
          is also a reference, but totally unrelated to any cell-references
          (cell-pointers) owned by the dataGridView object. With this, in
          consideration, can you explain the inner-working of
          >
          >
          dataGridView1.C urrentCellAddre ss = new Point(1, 1);
          >
          >
          >
          >
          Thanks for your time
          Vanderghast, Access MVP
          >
          >
          >
          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
          in message news:C3DF6C2C-724E-4B6A-8A17-C86C03A8F235@mi crosoft.com...
          >Michael,
          >>
          > There are more succinct ways of doing this:
          >>
          >dataGridView1. CurrentCellAddr ess = new Point(1, 1);
          >>
          > Or, if you wish:
          >>
          >dataGridView1. CurrentCell = dataGridView1[1, 1];
          >>
          > Both should have the same effect, although the top example will help
          >prevent unsharing of rows, which is good when you are using the grid in
          >virtual mode.
          >>
          >>
          >--
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >>
          >
          >

          Comment

          Working...