Click here to Skip to main content
16,020,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to update data grid view data from another class. I tried but some error is came.. Some one can help me how to do this....?

What I have tried:

'//This is another class

Public Class dataUpdate

private MyMainClassObj as Form1

public sub setGrid()
MyMainClassObj.DatagridView1.Rows(0).Cell(1).Value = "256"
end sub

End Class


'// In Main Class

Public Class Form1

private DataUpdateObj as dataUpdate


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

DataUpdateObj .setGrid()


End Sub


End Class
Posted
Comments
Richard chiu 30-Jun-16 22:38pm    
it seems like you haven't pass Form1 to dataUpdate instance when initializing it (in your dataUpdate class there is no way to pass Form1 so you will need to add an initializer) and also make sure you have a datagridview named DatagridView1 in Form1. Another way of doing this would be adding a parameter to setGrid() and passing it the DatagridView1 control.

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