Link to home
Start Free TrialLog in
Avatar of justinwood88
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.DataGrid.HitTestInfo
        HitTestInfo = grdActionItem_RevisitDate.HitTest(e.X, e.Y)
       
        If System.Windows.Forms.DataGrid.HitTestType.Cell And HitTestInfo.Column = 1 Then
            Dim frmCalander As New frmCalander
            GridHitTestInfo.ActionItemHitTestInfo = 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(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles Calander.DateSelected
        Dim frmMain As New frmMain
        frmMain.ActionItemDate.ActionItemDate = e.Start
        frmMain.dgrdActionItem.DataSource = frmMain.DsActionItem1
     
frmMain.dgrdActionItem.Item(frmMain.GridHitTestInfo.ActionItemHitTestInfo.Row,     frmMain.GridHitTestInfo.ActionItemHitTestInfo.Column) = e.Start
        Me.Close()
    End Sub

im not sure how else to go about this any help would be killer
Thanks JW
Avatar of karthikeyanTP
karthikeyanTP

Hai,

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
Avatar of justinwood88

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
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(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles Calander.DateSelected


        frmMain.ActionItemDate.ActionItemDate = e.Start
        CType(objForm, frmMain).dgrdActionItem.Item(frmMain.GridHitTestInfo.ActionItemHitTestInfo.Row, frmMain.GridHitTestInfo.ActionItemHitTestInfo.Column) = e.Start
        'frmMain.dgrdActionItem.Item(frmMain.GridHitTestInfo.ActionItemHitTestInfo.Row, frmMain.GridHitTestInfo.ActionItemHitTestInfo.Column) = e.Start

        Me.Close()
    End Sub
End Class

Private Sub dgrdActionItem_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgrdActionItem.MouseDown
        Dim grdActionItem_RevisitDate As DataGrid = CType(sender, DataGrid)
        Dim HitTestInfo As System.Windows.Forms.DataGrid.HitTestInfo
        HitTestInfo = grdActionItem_RevisitDate.HitTest(e.X, e.Y)
       
        If System.Windows.Forms.DataGrid.HitTestType.Cell And HitTestInfo.Column = 1 Then
            Dim frmCalander As New frmCalander
            MsgBox(HitTestInfo.Column)
            GridHitTestInfo.ActionItemHitTestInfo = HitTestInfo

**************Here is the Line I was Missing********************************
            frmCalander.objForm = Me
********************************************************************
            frmCalander.TopMost = True
            frmCalander.Show()
            frmCalander.WindowState = FormWindowState.Normal
            'grdActionItem_RevisitDate.Item(HitTestInfo.Row, HitTestInfo.Column) = ActionItemDate.ActionItemDate
        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
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial