vb.net - DataGridView Copy a selected row issue -


i have datagridview , want copy exact row gets selected user same position (above). have right inserts line above current line selected not copying values. i'm using basic grid, no dataset or datatables. heres code.

       if dgvpcprevmonth.selectedrows.count > 0         dgvpcprevmonth.rows.insert(dgvpcprevmonth.currentcell.rowindex,  dgvpcprevmonth.selectedrows(0).clone)     else         messagebox.show("select row before copy")     end if 

the clone method clones row, not data in it. you'll have loop through columns , add values after inserting it

public function clonewithvalues(byval row datagridviewrow) _     datagridviewrow      clonewithvalues = ctype(row.clone(), datagridviewrow)     index int32 = 0 row.cells.count - 1         clonewithvalues.cells(index).value = row.cells(index).value     next   end function 

the code taken directly msdn link provided below

https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.clone(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1


Comments