vb.net - record cellmouseclicks in a datagridview - use indexes of clicks made in datagridview as indexes in a matrix or array -


i hope me. many in advance.

my question related catching number of mouseclicks in datagridview. using visual basic in visual studio 2012.

i building matrix or array size 10x10 populated 1's. have datagridview same size. aim put 0 in place of matrix has same coordinates "rowindex" , "columnindex" click performed using mouse in datagridview. till point having success.

but want go further: want have many zeros in 1's matrix clicks on datagridview. problem can have 1 zero, last one.

if perform click in datagridview(1,1), datagridview(2,2) , datagridview(3,3) have 0 in place (3,3)

i not able record clicks made.

here have code:

      private sub clickmouse(sender object, e datagridviewcellmouseeventargs) handles datagridview.cellmouseclick     msgbox(e.clicks & e.columnindex & e.rowindex)     dim matrix integer(,) = populatematrix()      matrix(e.columnindex, e.rowindex) = 0      matrixtomatrixdef(matrix) end sub private function populatematrix() integer(,)       dim matrix(10, 10) integer     rown = 0 9         columnn = 0 9             matrix(columnn, rown) = 1         next     next     return matrix end function private sub matrixtomatrixdef(matrix integer(,))          dim matrixdef(10, 10) integer     rown = 0 9         columnn = 0 9             matrixdef(columnn, rown) = matrix(columnn, rown)             debug.write(matrixdef(columnn, rown).tostring & " ")         next         debug.writeline("")     next end sub 

you should define , populate matrix global variable, not inside clickmouse event handler (otherwise every click occurs deletes zeros set in previous one, leaving last one)

public class form1     private matrix integer(,) = populatematrix()      private sub clickmouse(sender object, e datagridviewcellmouseeventargs) handles datagridview.cellmouseclick         msgbox(e.clicks & e.columnindex & e.rowindex)          matrix(e.columnindex, e.rowindex) = 0          matrixtomatrixdef(matrix)     end sub      private function populatematrix() integer(,)           dim matrix(10, 10) integer         rown = 0 9             columnn = 0 9                 matrix(columnn, rown) = 1             next         next         return matrix     end function      private sub matrixtomatrixdef(matrix integer(,))              dim matrixdef(10, 10) integer         rown = 0 9             columnn = 0 9                 matrixdef(columnn, rown) = matrix(columnn, rown)                 debug.write(matrixdef(columnn, rown).tostring & " ")             next             debug.writeline("")         next     end sub end class    

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -