vb.net -- winforms -- datagridview -- new row with data filled into some cells -- disappears -


when add new row datagridview, able add data cell, when go row mouse data disappears out of cell. code needed data stay?

private sub bindingnavigatoraddnewitem_click(sender system.object, e system.eventargs) handles bindingnavigatoraddnewitem.click      ' when new row entered add site id.     dim rrow integer = 0     rrow = dgvestimator2.newrowindex      '' set job site id     if isdbnull(me.dgvestimator2(1, rrow).value) or isnothing(me.dgvestimator2(1,       rrow).value)         me.dgvestimator2(1, rrow).value = rjobsiteid         ' .rows(dgvrow).cells(1).value = objsheet.cells(excelrow, 1).value           me.dgvestimator2.rows(rrow).cells(1).value = rjobsiteid         ' me.dgvestimator2.rows(rrow).cells(1).selected = true         'datagridview1.rows[rowindex].selected = true         me.dgvestimator2.rows(rrow).selected = true         ' dgvestimator2.rows(rrow).setvalues()         dgvestimator2.commitedit(datagridviewdataerrorcontexts.commit)      end if 

end sub

thanks in advance!

it isn't entirely clear trying achieve sounds want set default values new row?

you shouldn't need use button - new row should show @ bottom of grid when have allowuserstoaddrows set true. there event raised when new row needs default values , there can populate cells like.

private sub datagridview1_defaultvaluesneeded(byval sender object, _ byval e system.windows.forms.datagridviewroweventargs) _ handles datagridview1.defaultvaluesneeded      dim index integer     index = datagridview1.newrowindex + 1      e.row.cells("column1").value = index.tostring()  end sub 

the cells still editable - can change them readonly if want, idea id columns.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -