Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code, but need to modify it to add after the selected row instead at the end. I can't seem to figure out how to modify to do this.


I thought it had to do something with the last line fillgridrow, but wasn't able to get it working. Any help would be appreciated.

Thanks

What I have tried:

private void button1_Click(object sender, EventArgs e)
       {
           DataGridViewRow dgr = dataGridView1.Rows[dataGridView1.CurrentRow.Index];

           DataRow dr = itemsDT.Rows[(int)dgr.Cells["idx"].Value];

           hiseq++;
           AddRepeatItem(dr); //sql query to insert into table
           GetNewItem();  //sql query to select newly added item

           if (newitemDT.Rows.Count == 0)
           {
               MessageBox.Show("Error writing repeat item entry. Call Systems. ");
           }
           DataRow dr2 = newitemDT.Rows[0];
           //itemsDT.Rows.Add(dr2);
           itemsDT.ImportRow(dr2);
           FillGridRow(dr2, newitemDT.Rows.Count - 1);

       }
Posted
Comments
[no name] 18-Apr-19 11:22am    
Custom code with no obvious connection to realty is nonsense to a 3rd party.
Member 14315552 18-Apr-19 11:26am    
how can I make it more helpful?
[no name] 18-Apr-19 11:58am    
ImportRow() doesn't "insert" it "adds" to the end. You need to read more.

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/adding-data-to-a-datatable

https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.importrow?view=netframework-4.7.2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900