justinwood88
asked on
Passing a value from one form to a datagrid on another form
Hi,
I have a form with a datagrid and when the datagrid is Mouse down event I capture the Hit Info in a class. I also open a form that has a calander on it. I want to take the selected date and put it in the cell they click on. But when I try to place the value from frmCalander into the form that has the datagrid I get a error saying that the data grid must be bound to a datatable. Here is my code.
main form
Dim grdActionItem_RevisitDate As DataGrid = CType(sender, DataGrid)
Dim HitTestInfo As System.Windows.Forms.DataG rid.HitTes tInfo
HitTestInfo = grdActionItem_RevisitDate. HitTest(e. X, e.Y)
If System.Windows.Forms.DataG rid.HitTes tType.Cell And HitTestInfo.Column = 1 Then
Dim frmCalander As New frmCalander
GridHitTestInfo.ActionItem HitTestInf o = HitTestInfo 'This is a class I created to capture the hit info
frmCalander.TopMost = True
frmCalander.Show()
frmCalander.WindowState = FormWindowState.Normal
End If
frmCalander*************** ***
Private Sub Calander_DateSelected(ByVa l sender As Object, ByVal e As System.Windows.Forms.DateR angeEventA rgs) Handles Calander.DateSelected
Dim frmMain As New frmMain
frmMain.ActionItemDate.Act ionItemDat e = e.Start
frmMain.dgrdActionItem.Dat aSource = frmMain.DsActionItem1
frmMain.dgrdActionItem.Ite m(frmMain. GridHitTes tInfo.Acti onItemHitT estInfo.Ro w, frmMain.GridHitTestInfo.Ac tionItemHi tTestInfo. Column) = e.Start
Me.Close()
End Sub
im not sure how else to go about this any help would be killer
Thanks JW
I have a form with a datagrid and when the datagrid is Mouse down event I capture the Hit Info in a class. I also open a form that has a calander on it. I want to take the selected date and put it in the cell they click on. But when I try to place the value from frmCalander into the form that has the datagrid I get a error saying that the data grid must be bound to a datatable. Here is my code.
main form
Dim grdActionItem_RevisitDate As DataGrid = CType(sender, DataGrid)
Dim HitTestInfo As System.Windows.Forms.DataG
HitTestInfo = grdActionItem_RevisitDate.
If System.Windows.Forms.DataG
Dim frmCalander As New frmCalander
GridHitTestInfo.ActionItem
frmCalander.TopMost = True
frmCalander.Show()
frmCalander.WindowState = FormWindowState.Normal
End If
frmCalander***************
Private Sub Calander_DateSelected(ByVa
Dim frmMain As New frmMain
frmMain.ActionItemDate.Act
frmMain.dgrdActionItem.Dat
frmMain.dgrdActionItem.Ite
Me.Close()
End Sub
im not sure how else to go about this any help would be killer
Thanks JW
ASKER
That is my primary goal but unfortunately, I have today to solve this problem and implement it through out my project. This web sit is exactly what I will do in the future but time restraints have caused me to find a quick fix. I’m trying to pass a value from a second form to the first's forms datagrid.
JW
JW
ASKER
I Figured It out!!!!!
This is what I was missing.
I forgot to set the frmCalanders frmMain Object to the instance of it self on frmMain. I think I said that right.
Public Class frmCalander
Inherits System.Windows.Forms.Form
Public objForm As Object
Private Sub Calander_DateSelected(ByVa l sender As Object, ByVal e As System.Windows.Forms.DateR angeEventA rgs) Handles Calander.DateSelected
frmMain.ActionItemDate.Act ionItemDat e = e.Start
CType(objForm, frmMain).dgrdActionItem.It em(frmMain .GridHitTe stInfo.Act ionItemHit TestInfo.R ow, frmMain.GridHitTestInfo.Ac tionItemHi tTestInfo. Column) = e.Start
'frmMain.dgrdActionItem.It em(frmMain .GridHitTe stInfo.Act ionItemHit TestInfo.R ow, frmMain.GridHitTestInfo.Ac tionItemHi tTestInfo. Column) = e.Start
Me.Close()
End Sub
End Class
Private Sub dgrdActionItem_MouseDown(B yVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles dgrdActionItem.MouseDown
Dim grdActionItem_RevisitDate As DataGrid = CType(sender, DataGrid)
Dim HitTestInfo As System.Windows.Forms.DataG rid.HitTes tInfo
HitTestInfo = grdActionItem_RevisitDate. HitTest(e. X, e.Y)
If System.Windows.Forms.DataG rid.HitTes tType.Cell And HitTestInfo.Column = 1 Then
Dim frmCalander As New frmCalander
MsgBox(HitTestInfo.Column)
GridHitTestInfo.ActionItem HitTestInf o = HitTestInfo
**************Here is the Line I was Missing******************* ********** ***
frmCalander.objForm = Me
************************** ********** ********** ********** ********** **
frmCalander.TopMost = True
frmCalander.Show()
frmCalander.WindowState = FormWindowState.Normal
'grdActionItem_RevisitDate .Item(HitT estInfo.Ro w, HitTestInfo.Column) = ActionItemDate.ActionItemD ate
End If
End Sub
Thanks karthikeyanTP for that link I will use it in the future for more than just the datapicker. I am assuming that it will work for combo boxs and other controls alike
Thanks
JW
This is what I was missing.
I forgot to set the frmCalanders frmMain Object to the instance of it self on frmMain. I think I said that right.
Public Class frmCalander
Inherits System.Windows.Forms.Form
Public objForm As Object
Private Sub Calander_DateSelected(ByVa
frmMain.ActionItemDate.Act
CType(objForm, frmMain).dgrdActionItem.It
'frmMain.dgrdActionItem.It
Me.Close()
End Sub
End Class
Private Sub dgrdActionItem_MouseDown(B
Dim grdActionItem_RevisitDate As DataGrid = CType(sender, DataGrid)
Dim HitTestInfo As System.Windows.Forms.DataG
HitTestInfo = grdActionItem_RevisitDate.
If System.Windows.Forms.DataG
Dim frmCalander As New frmCalander
MsgBox(HitTestInfo.Column)
GridHitTestInfo.ActionItem
**************Here is the Line I was Missing*******************
frmCalander.objForm = Me
**************************
frmCalander.TopMost = True
frmCalander.Show()
frmCalander.WindowState = FormWindowState.Normal
'grdActionItem_RevisitDate
End If
End Sub
Thanks karthikeyanTP for that link I will use it in the future for more than just the datapicker. I am assuming that it will work for combo boxs and other controls alike
Thanks
JW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If your primary goal is to have a DateTimePicker (a calendar from which a user can select a date), you might probably look at the following link which addresses the issue of adding a datetimepicker in a datagrid.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridcolumnstyleclasstopic.asp
Good luck