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. Keeping current new row in DataGridView on deactivate

Keeping current new row in DataGridView on deactivate

Scheduled Pinned Locked Moved C#
csssaleshelptutorialquestion
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.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    To reproduce: 1. Run code 2. Press down arrow 3. Click in second form title 4. Click in first form title 5. Enter some characters Observed: Entered data appears in first row Expected: Entered data should appear in second row How to fix ? using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; class TestApplication { static void Main() { var p = new Form(); p.IsMdiContainer = true; p.WindowState = FormWindowState.Maximized; var f1 = new TestForm(); var f2 = new Form(); f2.MdiParent = p; f1.MdiParent = p; f1.Show(); f2.StartPosition = FormStartPosition.Manual; f2.Left = 300; f2.Show(); Application.Run(p); } } class TestForm : Form { internal DataGridView grid = new DataGridView(); internal List<Customer> list; public TestForm() { Controls.Add(grid); BindingSource BindingSource = new BindingSource(); list = new List<Customer>(); list.Add(new Customer() { Name = "test" }); BindingList<Customer> bindingList = new BindingList<Customer>(list); BindingSource.DataSource = bindingList; grid.DataSource = bindingList; } } class Customer { public string Name { get; set; } }

    Andrus

    X 1 Reply Last reply
    0
    • A AndrusM

      To reproduce: 1. Run code 2. Press down arrow 3. Click in second form title 4. Click in first form title 5. Enter some characters Observed: Entered data appears in first row Expected: Entered data should appear in second row How to fix ? using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; class TestApplication { static void Main() { var p = new Form(); p.IsMdiContainer = true; p.WindowState = FormWindowState.Maximized; var f1 = new TestForm(); var f2 = new Form(); f2.MdiParent = p; f1.MdiParent = p; f1.Show(); f2.StartPosition = FormStartPosition.Manual; f2.Left = 300; f2.Show(); Application.Run(p); } } class TestForm : Form { internal DataGridView grid = new DataGridView(); internal List<Customer> list; public TestForm() { Controls.Add(grid); BindingSource BindingSource = new BindingSource(); list = new List<Customer>(); list.Add(new Customer() { Name = "test" }); BindingList<Customer> bindingList = new BindingList<Customer>(list); BindingSource.DataSource = bindingList; grid.DataSource = bindingList; } } class Customer { public string Name { get; set; } }

      Andrus

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      As far as i understood, you wanna say that you are writing something in a DGV's new row then you click on another form and back to that first form now when you write, it should be in second row. Well, if 'Yes' then just write this code in that Form's Deactivate Event

      dataGridView1.CurrentCell = dataGridView1[0, dataGridView1.RowCount - 1];

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      A 1 Reply Last reply
      0
      • X Xmen Real

        As far as i understood, you wanna say that you are writing something in a DGV's new row then you click on another form and back to that first form now when you write, it should be in second row. Well, if 'Yes' then just write this code in that Form's Deactivate Event

        dataGridView1.CurrentCell = dataGridView1[0, dataGridView1.RowCount - 1];

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        A Offline
        A Offline
        AndrusM
        wrote on last edited by
        #3

        Thank you. Two issues: 1. In real-application second form may be activated when some other form, not this form containing grid is activated. There may be also a lot of forms like first form. How to use deactivate in this case? 2. If second form is activated, grid in first form visually shows that current row is first row by putting triangle to first row. How to prevent this so that current row triangle remains in second, new row ?

        Andrus

        X 1 Reply Last reply
        0
        • A AndrusM

          Thank you. Two issues: 1. In real-application second form may be activated when some other form, not this form containing grid is activated. There may be also a lot of forms like first form. How to use deactivate in this case? 2. If second form is activated, grid in first form visually shows that current row is first row by putting triangle to first row. How to prevent this so that current row triangle remains in second, new row ?

          Andrus

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #4

          did you tried the code i gave you and i dont get what are you trying to say. Explain in points

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          A 1 Reply Last reply
          0
          • X Xmen Real

            did you tried the code i gave you and i dont get what are you trying to say. Explain in points

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

            A Offline
            A Offline
            AndrusM
            wrote on last edited by
            #5

            I tried your code and got the following issue: Observed: After activating second window grid current record marker jumps to first row:

            > test
            *

            Exprected: Current row marker should remain in last row:

            test

            *

            Andrus

            X 1 Reply Last reply
            0
            • A AndrusM

              I tried your code and got the following issue: Observed: After activating second window grid current record marker jumps to first row:

              > test
              *

              Exprected: Current row marker should remain in last row:

              test

              *

              Andrus

              X Offline
              X Offline
              Xmen Real
              wrote on last edited by
              #6

              now it wont, you did something wrong. The code i gave you will always set the focus to last row

              TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

              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