[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing a value from one form to a datagrid on another form

Posted on 2004-11-05
5
Medium Priority
?
179 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:justinwood88
  • 2
4 Comments
 
LVL 2

Expert Comment

by:karthikeyanTP
ID: 12511869
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
0
 

Author Comment

by:justinwood88
ID: 12513622
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
0
 

Author Comment

by:justinwood88
ID: 12513733
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
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12799406
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question