Keeping current new row in DataGridView on deactivate
-
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
-
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
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
EventdataGridView1.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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
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
EventdataGridView1.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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
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
-
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
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
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
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can