Results 1 to 11 of 11

Thread: [RESOLVED] DataGridView1.cellmousedoubleclick

  1. #1

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Resolved [RESOLVED] DataGridView1.cellmousedoubleclick

    okay I looked everywhere to see why the debugger is telling me:

    Error 22 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    all the code snipets I looked at don't use it

    here is my code concerning the datagrid I am using:

    2010 Code:
    1. Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    2.  
    3.         DtgResult = New System.Windows.Forms.DataGridView
    4.  
    5.         With DtgResult
    6.  
    7.             .Location = New System.Drawing.Point(0, 0)
    8.             .Name = "PnlDataGrid"
    9.             .Size = New System.Drawing.Size(1077, 456)
    10.             .TabIndex = 6
    11.             '.ColumnCount = 7
    12.  
    13.             .EditMode = DataGridViewEditMode.EditOnEnter
    14.             .AutoSizeRowsMode = _
    15.                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    16.             .ColumnHeadersBorderStyle = _
    17.                 DataGridViewHeaderBorderStyle.Raised
    18.             .CellBorderStyle = _
    19.                 DataGridViewCellBorderStyle.Single
    20.             .GridColor = SystemColors.ActiveBorder
    21.             .RowHeadersVisible = False
    22.             .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    23.             .MultiSelect = False
    24.             .Dock = DockStyle.Fill
    25. End With
    26.  
    27. 'some more codes for SQL selection
    28.  
    29.         Dim SQLString As String = "SELECT N°,Nom, Prenom, Cour1, Cour2, Cour3, ArtGrade, Lieu, DateRenouvellement  from " & DSTable & " WHERE " & Choice1
    30.         Dim dsReturn As DataSet = DataModule.DBDataAcess(SQLString, DSTable)
    31.         DataModule.DBDataAcess(SQLString, DSTable)
    32.         With DtgResult
    33.             .DataSource = dsReturn.Tables(0)
    34. End Sub

    So this is where my datagridview is created, next I am trying the following:

    2010 Code:
    1. Private Sub DtgResult_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles [B]DtgResult[/B].cellmousedoubleclick
    2.  
    3.     End Sub
    as soon as I type DtgResult the error msg appears
    The other problem is that I never worked with the "withevent" and have no idea how and where I have to put it in my code after checking the examples from msdn

    thank you for your time as usual
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: DataGridView1.cellmousedoubleclick

    Quote Originally Posted by Jomahtr View Post
    The other problem is that I never worked with the "withevent" and have no idea how and where I have to put it in my code after checking the examples from msdn
    I don't understand how that could be. I just searched MSDN for withevents and this was the second result:

    http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx

    That shows you exactly how to use WithEvents. What exactly do you not understand about that?

  3. #3

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Re: DataGridView1.cellmousedoubleclick

    Here is what is on msdn:

    2010 Code:
    1. ' Declare a WithEvents variable.
    2. Dim WithEvents EClass As New EventClass
    3.  
    4. ' Call the method that raises the object's events.
    5. Sub TestEvents()
    6.     EClass.RaiseEvents()
    7. End Sub
    8.  
    9. ' Declare an event handler that handles multiple events.
    10. Sub EClass_EventHandler() Handles EClass.XEvent, EClass.YEvent
    11.     MsgBox("Received Event.")
    12. End Sub
    13.  
    14. Class EventClass
    15.     Public Event XEvent()
    16.     Public Event YEvent()
    17.     ' RaiseEvents raises both events.
    18.     Sub RaiseEvents()
    19.         RaiseEvent XEvent()
    20.         RaiseEvent YEvent()
    21.     End Sub
    22. End Class

    I tried to change it to fit it in my code as followed:

    2010 Code:
    1. ' Declare a WithEvents variable.
    2. Dim WithEvents DtgResult As New EventClass
    3.  
    4. ' Call the method that raises the object's events.
    5. Sub TestEvents()
    6.     DtgResult.RaiseEvents()
    7. End Sub
    8.  
    9. ' Declare an event handler that handles multiple events.
    10. Sub DtgResult_EventHandler() Handles DtgResult.cellmousedoubleclick
    11.     'MsgBox("Received Event.")
    12. End Sub
    13.  
    14. Class EventClass
    15.     Public Event cellmousedoubleclick()
    16.    
    17.     ' RaiseEvents raises both events.
    18.     Sub RaiseEvents()
    19.         RaiseEvent cellmousedoubleclick()
    20.        
    21.     End Sub
    22. End Class

    First thing is that when I declare DtgResult with Dim WithEvents DtgResult I get the following error:


    Error 22 'DtgResult' is already declared as 'Private DtgResult As Object' in this class.

    which is normal since I already declared it as Dim DtgResult As Object.

    But if I remove that declaration, the rest of DtgResult does't seem to act as a DataGridView object since all my properties return errors and I get this error as well:

    Error 41 Method 'Private Sub DtgResult_CellMouseDoubleClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs)' cannot handle event 'Public Event cellmousedoubleclick()' because they do not have a compatible signature.

    This is pretty much where I am confused
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: DataGridView1.cellmousedoubleclick

    You've completely misread what that example is doing. It shows a class, i.e. EventClass, that has events, i.e. XEvent and YEvent. It shows a variable of that type, i.e. EClass, declared WithEvents and then a method with a Handles clause, i.e. EClass_EventHandler, that handles those events. How does that map to your situation? You have a class, i.e. DataGridView, that has an event, i.e. CellMouseDoubleClick. You have a variable of that type, i.e. DtgResult, and then a method with a Handles clause, i.e. DtgResult_CellMouseDoubleClick, that handles that event. The one and only thing that you haven't done, as the original error message says, is declare the variable WithEvents. All you had to do is add one word:
    Code:
    Dim WithEvents DtgResult As DataGridView

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: DataGridView1.cellmousedoubleclick

    Having said all that, I don't really understand why you're creating the grid in code anyway. Why not just add it to the form in the designer? That way the WithEvents variable would be declared automatically for you, amongst other things.

  6. #6

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Re: DataGridView1.cellmousedoubleclick

    I think I get it,

    I reverted my code to the way it was and I changed the declaration to
    Code:
    Dim WithEvents DtgResult As DataGridView
    there is one thing I don't understand thought, since CellMouseDoubleClick is a default datagridview event why am I getting the following error message?

    Error 22 Event 'CellMouseDoubleClick' cannot be found.

    I'm sorry if this seem stupid, this is my first project in .net and I haven't programmed in over 10 years back when OOC was in its first steps.
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

  7. #7

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Re: DataGridView1.cellmousedoubleclick

    As to why I created everything programmatically is out of old habit and to try to understand how to work with properties, you can check one of my previous post http://www.vbforums.com/showthread.php?t=663054 in which you participated as well.
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: DataGridView1.cellmousedoubleclick

    Learning how to work with properties is no reason to create a DataGridView in code. You're really doing this the hard way. Just add a DataGridView to the form and then use the Properties window or the drop-down lists at the top of the code window to create the desired event handlers.

  9. #9

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Re: DataGridView1.cellmousedoubleclick

    ok I figured why I got this error

    I was declaring my datagridview as an object at first then changed it later from object to datagridview.

    for whoever is crazy enough to do it programmatically like I did here is the complete code. Just bear in mind that when my form load I only have the ComboBox Form_searchBy that is created. Also Only the first ComboBox with the "Art Martial" choice and the 2 others empty will return a result at this time since the other choices are not implemented yet (For testing purpose)

    Trust me I've learned my lesson concerning creating controls during runtime.

    Thank you very much jmcilhinney for your time and explanation

    VB Code:
    1. Public Class Student_search
    2.     Dim Decision() As String = {"", "Nom", "Art martial", "Degré", "Date de renouvellement", "Dojo"}
    3.     Dim Searchbox1 As Object
    4.     Dim Searchbox2 As Object
    5.     Dim Searchbox3 As Object
    6.     Dim Searchbox4 As Object
    7.     Dim Searchbox5 As Object
    8.     Dim Searchbox6 As Object
    9.     Dim WithEvents SearchRef1 As New ComboBox
    10.     Dim WithEvents SearchRef2 As New ComboBox
    11.     Dim SearchBoxLab1 As Object
    12.     Dim SearchBoxLab2 As Object
    13.     Dim SearchRefLab1 As Object
    14.     Dim SearchRefLab2 As Object
    15.     Dim SearchRefLab3 As Object
    16.     Dim PnlGroup1 As Object
    17.     Dim PnlGroup2 As New Object
    18.     Dim PnlDataGrid As Object
    19.     Dim WithEvents DtgResult As DataGridView
    20.     Dim Degrée = New System.Windows.Forms.DataGridViewTextBoxColumn()
    21.     Dim Rnouvellement = New System.Windows.Forms.DataGridViewTextBoxColumn()
    22.     Dim Dojo = New System.Windows.Forms.DataGridViewTextBoxColumn()
    23.     Dim Art_Martial = New System.Windows.Forms.DataGridViewTextBoxColumn()
    24.     Dim Prénom = New System.Windows.Forms.DataGridViewTextBoxColumn()
    25.     Dim Nom = New System.Windows.Forms.DataGridViewTextBoxColumn()
    26.     Dim ID = New System.Windows.Forms.DataGridViewTextBoxColumn()
    27.  
    28.     Private Sub ClearCheck(ByRef Container As Control)
    29.         'clear all the control when the value of the first ComboBox is changed
    30.         For x As Integer = Container.Controls.Count - 1 To 0 Step -1
    31.             Dim ctrl As Control = DirectCast(Container.Controls(x), Control)
    32.             If ctrl.Name <> "Form_searchBy" _
    33.                 And ctrl.Name <> "Label1" _
    34.                 And ctrl.Name <> "btnSearch" _
    35.                 And ctrl.Name <> "btnReset" Then
    36.  
    37.                 Me.Controls.Remove(ctrl)
    38.  
    39.             End If
    40.         Next
    41.     End Sub
    42.  
    43.     Private Sub ClearCheck2(ByRef Container As Control)
    44.         'clear all the control in pannel containing second and third ComboBox when the value of the second ComboBox is changed
    45.         For x As Integer = Container.Controls.Count - 1 To 0 Step -1
    46.             Dim ctrl As Control = DirectCast(Container.Controls(x), Control)
    47.  
    48.             If Not ctrl.Name = "SearchRef1" _
    49.                 And Not ctrl.Name = "SearchRefLab1" Then
    50.                 Me.PnlGroup1.Controls.Remove(ctrl)
    51.                 Me.Controls.Remove(PnlGroup2)
    52.             End If
    53.  
    54.             Me.SearchRef2.Text = ""
    55.         Next
    56.  
    57.     End Sub
    58.  
    59.     Private Sub ClearCheck3(ByRef Container As Control)
    60.         'clear all the control in pannel containing third ComboBox when the value of the third ComboBox is changed
    61.         For x As Integer = Container.Controls.Count - 1 To 0 Step -1
    62.             Dim ctrl As Control = DirectCast(Container.Controls(x), Control)
    63.             If Not ctrl.Name = "SearchRef2" _
    64.                 And Not ctrl.Name = "SearchRefLab2" Then
    65.                 Me.PnlGroup2.Controls.Remove(ctrl)
    66.  
    67.             End If
    68.         Next
    69.     End Sub
    70.  
    71.     Private Sub Student_search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    72.         Form_searchBy.Items.Clear()
    73.         Form_searchBy.Items.AddRange(Decision)
    74.         Me.Refresh()
    75.     End Sub
    76.  
    77.     Private Sub Form_searchBy_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form_searchBy.SelectedIndexChanged
    78.  
    79.         ClearCheck(Me.TopLevelControl)
    80.         Me.Update()
    81.         Me.Refresh()
    82.  
    83.         Select Case (Form_searchBy.Text) 'change the behaviour depending on what is selected in the combobox
    84.  
    85.             Case "Art martial"
    86.                 Dim DSTable As String = "Config_cours"
    87.                 Dim SQLString As String = "Select * From " & DSTable & " ORDER By Cours"
    88.                 Dim dsReturn As DataSet = DataModule.DBDataAcess(SQLString, DSTable)
    89.  
    90.                 Searchbox1 = New System.Windows.Forms.ComboBox
    91.                 With Searchbox1
    92.                     .Name = "searchbox1"
    93.                     .Location = New Point(12, 56)
    94.                     .Width = 145
    95.                     .Height = 21
    96.                     .DataSource = DataModule.DBDataAcess(SQLString, DSTable).Tables(0)
    97.                     .DisplayMember = "Cours"
    98.                     .ValueMember = "No"
    99.                     .parent = Form_searchBy
    100.                     .Visible = True
    101.                     .Show()
    102.                     .update()
    103.  
    104.                 End With
    105.                 Me.Controls.Add(Searchbox1)
    106.                 Me.Update()
    107.                 Me.Refresh()
    108.  
    109.             Case "Nom"
    110.  
    111.                 'Create name box label
    112.                 SearchBoxLab1 = New System.Windows.Forms.Label
    113.                 With SearchBoxLab1
    114.                     .Name = "SearchBoxLab1"
    115.                     .Location = New Point(13, 53)
    116.                     .height = 13
    117.                     .Text = "Nom"
    118.                     .parent = Form_searchBy
    119.                 End With
    120.                 Me.Controls.Add(SearchBoxLab1)
    121.  
    122.                 'Create Name search box
    123.                 Searchbox1 = New System.Windows.Forms.TextBox
    124.                 With Searchbox1
    125.                     .Name = "searchbox1"
    126.                     .Location = New Point(13, 69)
    127.                     .Width = 145
    128.                     .Height = 21
    129.                     .parent = Form_searchBy
    130.                     .Visible = True
    131.                     .Show()
    132.                     .update()
    133.                 End With
    134.                 Me.Controls.Add(Searchbox1)
    135.  
    136.                 'Create first name box label
    137.                 SearchBoxLab2 = New System.Windows.Forms.Label
    138.                 With SearchBoxLab2
    139.                     .Name = "SearchBoxLab2"
    140.                     .Location = New Point(13, 93)
    141.                     .height = 13
    142.                     .Text = "Prénom"
    143.                     .parent = Form_searchBy
    144.  
    145.                 End With
    146.                 Me.Controls.Add(SearchBoxLab2)
    147.  
    148.                 'Create first Name search box
    149.                 Searchbox2 = New System.Windows.Forms.TextBox
    150.                 With Searchbox2
    151.                     .Name = "searchbox2"
    152.                     .Location = New Point(13, 109)
    153.                     .Width = 145
    154.                     .Height = 21
    155.                     .parent = Form_searchBy
    156.                     .Visible = True
    157.                     .Show()
    158.                     .update()
    159.                 End With
    160.                 Me.Controls.Add(Searchbox2)
    161.  
    162.         End Select
    163.  
    164.         If Form_searchBy.Text <> "" Then
    165.             PnlGroup1 = New System.Windows.Forms.Panel ' Create the first pannel containing the Third ComboBox and it's generated controls
    166.             With PnlGroup1
    167.                 .location = New Point(163, 0)
    168.                 .width = 146
    169.                 .height = 140
    170.                 .name = "PnlGroup1"
    171.  
    172.             End With
    173.  
    174.             'Create the second ComboBox when a choice is selected in the first one
    175.             SearchRef1 = New System.Windows.Forms.ComboBox
    176.             SearchRef1.Items.Clear()
    177.             With SearchRef1
    178.                 .Name = "SearchRef1"
    179.                 .Location = New Point(0, 29)
    180.                 .Width = 145
    181.                 .Height = 21
    182.                 .Items.AddRange(Me.Decision)
    183.                 .Items.Remove(Me.Form_searchBy.Text) 'Remove the choice from the first ComboBox
    184.                 .Text = ""
    185.                 .BringToFront()
    186.  
    187.             End With
    188.  
    189.             SearchRefLab1 = New System.Windows.Forms.Label
    190.             With SearchRefLab1
    191.                 .Name = "SearchRefLab1"
    192.                 .Location = New Point(0, 13)
    193.                 .Text = "Affiner la recherche (Optionnel)"
    194.                 .backcolor = Color.Transparent
    195.                 .parent = PnlGroup1
    196.             End With
    197.  
    198.             PnlGroup1.controls.add(SearchRef1)
    199.             PnlGroup1.controls.add(SearchRefLab1)
    200.             Me.Controls.Add(PnlGroup1)
    201.  
    202.             Me.Update()
    203.             Me.Refresh()
    204.  
    205.         End If
    206.  
    207.     End Sub
    Last edited by Jomahtr; Oct 22nd, 2011 at 12:38 AM. Reason: Wrong Highlight
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

  10. #10

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Re: DataGridView1.cellmousedoubleclick

    Code part 2

    vb Code:
    1. Private Sub SearchRef1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchRef1.SelectedIndexChanged
    2.  
    3.         ClearCheck2(Me.PnlGroup1)
    4.  
    5.         If TypeOf (PnlGroup2) Is Panel Then
    6.             ClearCheck2(Me.PnlGroup2)
    7.         End If
    8.  
    9.         Me.Update()
    10.         Me.Refresh()
    11.  
    12.         Select Case (SearchRef1.Text) 'change the behaviour depending on what is selected in the combobox
    13.  
    14.             Case "Art martial"
    15.                 Dim DSTable As String = "Config_cours"
    16.                 Dim SQLString As String = "Select * From " & DSTable & " ORDER By Cours"
    17.                 Dim dsReturn As DataSet = DataModule.DBDataAcess(SQLString, DSTable)
    18.  
    19.                 Searchbox3 = New System.Windows.Forms.ComboBox
    20.                 With Searchbox3
    21.                     .Name = "searchbox3"
    22.                     .Location = New Point(0, 56)
    23.                     .Width = 145
    24.                     .Height = 21
    25.                     .DataSource = DataModule.DBDataAcess(SQLString, DSTable).Tables(0)
    26.                     .DisplayMember = "Cours"
    27.                     .ValueMember = "No"
    28.                     ' .parent = PnlGroup1
    29.                     .Visible = True
    30.                     .Show()
    31.                     .update()
    32.  
    33.                 End With
    34.                 Me.PnlGroup1.Controls.Add(Searchbox3)
    35.                 Me.Update()
    36.                 Me.Refresh()
    37.  
    38.             Case "Nom"
    39.  
    40.                 'Create name box label
    41.                 SearchBoxLab1 = New System.Windows.Forms.Label
    42.                 With SearchBoxLab1
    43.                     .Name = "SearchBoxLab1"
    44.                     .Location = New Point(0, 53)
    45.                     .height = 13
    46.                     .Text = "Nom"
    47.                     ' .parent = PnlGroup1
    48.  
    49.                 End With
    50.                 Me.PnlGroup1.Controls.Add(SearchBoxLab1)
    51.  
    52.                 'Create Name search box
    53.                 Searchbox3 = New System.Windows.Forms.TextBox
    54.                 With Searchbox3
    55.                     .Name = "searchbox3"
    56.                     .Location = New Point(0, 69)
    57.                     .Width = 145
    58.                     .Height = 21
    59.                     ' .parent = PnlGroup1
    60.                     .Visible = True
    61.                     .Show()
    62.                     .update()
    63.                 End With
    64.                 Me.PnlGroup1.Controls.Add(Searchbox3)
    65.  
    66.                 'Create first name box label
    67.                 SearchBoxLab2 = New System.Windows.Forms.Label
    68.                 With SearchBoxLab2
    69.                     .Name = "SearchBoxLab2"
    70.                     .Location = New Point(0, 93)
    71.                     .height = 13
    72.                     .Text = "Prénom"
    73.                     ' .parent = PnlGroup1
    74.                 End With
    75.                 Me.PnlGroup1.Controls.Add(SearchBoxLab2)
    76.  
    77.                 'Create first Name search box
    78.                 Searchbox4 = New System.Windows.Forms.TextBox
    79.                 With Searchbox4
    80.                     .Name = "searchbox4"
    81.                     .Location = New Point(0, 109)
    82.                     .Width = 145
    83.                     .Height = 21
    84.                     ' .parent = PnlGroup1
    85.                     .Visible = True
    86.                     .Show()
    87.                     .update()
    88.                 End With
    89.                 Me.PnlGroup1.Controls.Add(Searchbox4)
    90.  
    91.         End Select
    92.  
    93.         If SearchRef1.Text <> "" Then
    94.  
    95.             PnlGroup2 = New System.Windows.Forms.Panel ' Create the second pannel containing the Third ComboBox and it's generated controls
    96.             With PnlGroup2
    97.                 .Location = New Point(314, 0)
    98.                 .Width = 146
    99.                 .Height = 140
    100.                 .Name = "PnlGroup2"
    101.  
    102.             End With
    103.  
    104.             SearchRef2 = New System.Windows.Forms.ComboBox
    105.             SearchRef2.Items.Clear()
    106.             With SearchRef2
    107.                 .Name = "SearchRef2"
    108.                 .Location = New Point(0, 29)
    109.                 .Width = 145
    110.                 .Height = 21
    111.                 .Items.AddRange(Decision)
    112.                 .Items.Remove(Form_searchBy.Text)
    113.                 .Items.Remove(SearchRef1.Text)
    114.                 .Text = ""
    115.             End With
    116.  
    117.             SearchRefLab2 = New System.Windows.Forms.Label
    118.             With SearchRefLab2
    119.                 .Name = "SearchRefLab2"
    120.                 .Location = New Point(0, 13)
    121.                 .Text = "Affiner la recherche (Optionnel)"
    122.             End With
    123.  
    124.             Me.PnlGroup2.Controls.Add(SearchRef2)
    125.             Me.PnlGroup2.Controls.Add(SearchRefLab2) ' remove the choice from the first and second ComboBox
    126.             Me.Controls.Add(PnlGroup2)
    127.  
    128.         End If
    129.  
    130.         Me.Update()
    131.         Me.Refresh()
    132.  
    133.     End Sub
    134.  
    135.     Private Sub SearchRef2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchRef2.SelectedIndexChanged
    136.  
    137.         ClearCheck3(Me.PnlGroup2)
    138.         Me.Update()
    139.         Me.Refresh()
    140.  
    141.         Select Case (SearchRef2.Text) 'change the behaviour depending on what is selected in the combobox
    142.  
    143.             Case "Art martial"
    144.                 Dim DSTable As String = "Config_cours"
    145.                 Dim SQLString As String = "Select * From " & DSTable & " ORDER By Cours"
    146.                 Dim dsReturn As DataSet = DataModule.DBDataAcess(SQLString, DSTable)
    147.  
    148.                 Searchbox5 = New System.Windows.Forms.ComboBox
    149.                 With Searchbox5
    150.                     .Name = "searchbox5"
    151.                     .Location = New Point(0, 56)
    152.                     .Width = 145
    153.                     .Height = 21
    154.                     .DataSource = DataModule.DBDataAcess(SQLString, DSTable).Tables(0)
    155.                     .DisplayMember = "Cours"
    156.                     .ValueMember = "No"
    157.                     ' .parent = PnlGroup1
    158.                     .Visible = True
    159.                     .Show()
    160.                     .update()
    161.  
    162.                 End With
    163.                 Me.PnlGroup2.controls.Add(Searchbox5)
    164.                 Me.Update()
    165.                 Me.Refresh()
    166.  
    167.             Case "Nom"
    168.  
    169.                 'Create name box label
    170.                 SearchBoxLab1 = New System.Windows.Forms.Label
    171.                 With SearchBoxLab1
    172.                     .Name = "SearchBoxLab1"
    173.                     .Location = New Point(0, 53)
    174.                     .height = 13
    175.                     .Text = "Nom"
    176.                     ' .parent = PnlGroup1
    177.  
    178.                 End With
    179.                 Me.PnlGroup2.controls.Add(SearchBoxLab1)
    180.  
    181.                 'Create Name search box
    182.                 Searchbox5 = New System.Windows.Forms.TextBox
    183.                 With Searchbox1
    184.                     .Name = "searchbox5"
    185.                     .Location = New Point(0, 69)
    186.                     .Width = 145
    187.                     .Height = 21
    188.                     ' .parent = PnlGroup1
    189.                     .Visible = True
    190.                     .Show()
    191.                     .update()
    192.                 End With
    193.                 Me.PnlGroup2.controls.Add(Searchbox5)
    194.  
    195.                 'Create first name box label
    196.                 SearchBoxLab2 = New System.Windows.Forms.Label
    197.                 With SearchBoxLab2
    198.                     .Name = "SearchBoxLab2"
    199.                     .Location = New Point(0, 93)
    200.                     .height = 13
    201.                     .Text = "Prénom"
    202.                     ' .parent = PnlGroup1
    203.                 End With
    204.                 Me.PnlGroup2.controls.Add(SearchBoxLab2)
    205.  
    206.                 'Create first Name search box
    207.                 Searchbox6 = New System.Windows.Forms.TextBox
    208.                 With Searchbox6
    209.                     .Name = "searchbox6"
    210.                     .Location = New Point(0, 109)
    211.                     .Width = 145
    212.                     .Height = 21
    213.                     ' .parent = PnlGroup1
    214.                     .Visible = True
    215.                     .Show()
    216.                     .update()
    217.                 End With
    218.                 Me.PnlGroup2.controls.Add(Searchbox6)
    219.  
    220.         End Select
    221.  
    222.         Me.Update()
    223.         Me.Refresh()
    224.  
    225.     End Sub
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

  11. #11

    Thread Starter
    Member Jomahtr's Avatar
    Join Date
    Sep 2011
    Location
    Quebec, Canada
    Posts
    37

    Re: DataGridView1.cellmousedoubleclick

    Code Part 3
    vb Code:
    1. Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    2.  
    3.         'Create the panel containing the DataGridView
    4.         PnlDataGrid = New System.Windows.Forms.Panel
    5.         With PnlDataGrid
    6.             .location = New Point(12, 146)
    7.             .width = 1077
    8.             .height = 456
    9.             .name = "PnlDataGrid"
    10.             .BorderStyle = BorderStyle.FixedSingle
    11.  
    12.  
    13.         End With
    14.  
    15.         DtgResult = New System.Windows.Forms.DataGridView 'Create the datagridview
    16.         With DtgResult
    17.  
    18.             .Location = New System.Drawing.Point(0, 0)
    19.             .Name = "DtgResult"
    20.             .Size = New System.Drawing.Size(1077, 456)
    21.             .TabIndex = 6
    22.             '.ColumnCount = 7
    23.  
    24.             .EditMode = DataGridViewEditMode.EditProgrammatically
    25.             .AutoSizeRowsMode = _
    26.                 DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
    27.             .ColumnHeadersBorderStyle = _
    28.                 DataGridViewHeaderBorderStyle.Raised
    29.             .CellBorderStyle = _
    30.                 DataGridViewCellBorderStyle.Single
    31.             .GridColor = SystemColors.ActiveBorder
    32.             .RowHeadersVisible = False
    33.             .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    34.             .MultiSelect = False
    35.             .Dock = DockStyle.Fill
    36.  
    37.  
    38.         End With
    39.  
    40.         Me.PnlDataGrid.Controls.Add(DtgResult)
    41.         Me.Controls.Add(PnlDataGrid)
    42.  
    43.         'Get result from database
    44.         Dim Choice1 As String = Nothing
    45.         Dim Choice2 As String = Nothing
    46.         Dim Choice3 As String = Nothing
    47.         Dim Choice4 As String = Nothing
    48.         Dim choice5 As String = Nothing
    49.         Dim Choice6 As String = Nothing
    50.         Dim DSTable As String = "Eleves"
    51.  
    52.         If TypeOf (PnlGroup2) Is Panel _
    53.             And SearchRef2.Text <> "" Then ' check if panel 2 exist
    54.  
    55.             If Not SearchRef2.Text Is "" _
    56.             And Not SearchRef1.Text Is "" _
    57.             And Not Me.Form_searchBy.Text Is "" Then
    58.  
    59.                 Select Case SearchRef2.Text
    60.  
    61.                     Case "Art martial"
    62.                         choice5 = Searchbox5.text
    63.                     Case "Nom"
    64.                         choice5 = Searchbox5.text
    65.                         Choice6 = Searchbox6.text
    66.                     Case "Dojo"
    67.                         choice5 = Searchbox5.text
    68.                     Case "Degré"
    69.                         choice5 = Searchbox5.text
    70.                     Case "Date de renouvellement"
    71.                         choice5 = Searchbox5.text
    72.                     Case Else
    73.                         MsgBox("Le choix que vous avez entré dans la deuxieme boîte de raffinement de la recherche est invalide")
    74.                         ClearCheck3(Me.PnlGroup2)
    75.                         Me.PnlDataGrid.DtgResult.controls.remove()
    76.                         Me.PnlDataGrid.controls.remove()
    77.                         Me.Update()
    78.                 End Select
    79.  
    80.                 Select Case SearchRef1.Text
    81.                     Case "Art martial"
    82.                         Choice3 = Searchbox3.text
    83.                     Case "Nom"
    84.                         Choice3 = Searchbox3.text
    85.                         Choice4 = Searchbox4.text
    86.                     Case "Dojo"
    87.                         Choice3 = Searchbox3.text
    88.                     Case "Degré"
    89.                         Choice3 = Searchbox3.text
    90.                     Case "Date de renouvellement"
    91.                         Choice3 = Searchbox3.text
    92.                     Case Else
    93.                         MsgBox("Le choix que vous avez entré dans la première boîte de raffinement de la recherche est invalide")
    94.                         Me.PnlDataGrid.DtgResult.controls.remove()
    95.                         Me.PnlDataGrid.controls.remove()
    96.                         Me.Update()
    97.  
    98.                 End Select
    99.  
    100.                 Select Case Form_searchBy.Text
    101.                     Case "Art martial"
    102.                         Choice1 = "Cour1 = " & Searchbox1.text & " OR Cour2 = " & Searchbox1 & " OR Cour3 = " & Searchbox1
    103.                     Case "Nom"
    104.                         Choice1 = Searchbox1.text
    105.                         Choice2 = Searchbox2.text
    106.                     Case "Dojo"
    107.                         Choice1 = Searchbox1.text
    108.                     Case "Degré"
    109.                         Choice1 = Searchbox1.text
    110.                     Case "Date de renouvellement"
    111.                         Choice1 = Searchbox1.text
    112.                     Case Else
    113.                         MsgBox("Le choix que vous avez entré dans la boîte de recherche est invalide")
    114.                         ClearCheck(Me.TopLevelControl)
    115.                 End Select
    116.             End If
    117.  
    118.         ElseIf TypeOf (PnlGroup1) Is Panel _
    119.             And SearchRef1.Text <> "" _
    120.             And Me.Form_searchBy.Text <> "" Then ' check if panel 1 exist and that second ComboBox is not empty
    121.  
    122.             Select Case SearchRef1.Text
    123.                 Case "Art martial"
    124.                     Choice3 = "Cour1 = " & Searchbox3.text & " OR Cour2 = " & Searchbox3 & " OR Cour3 = " & Searchbox1
    125.                 Case "Nom"
    126.                     Choice3 = Searchbox3.text
    127.                     Choice4 = Searchbox4.text
    128.                 Case "Dojo"
    129.                     Choice3 = Searchbox3.text
    130.                 Case "Degré"
    131.                     Choice3 = Searchbox3.text
    132.                 Case "Date de renouvellement"
    133.                     Choice3 = Searchbox3.text
    134.                 Case Else
    135.                     MsgBox("Le choix que vous avez entré dans la première boîte de raffinement de la recherche est invalide")
    136.                     ClearCheck2(Me.PnlGroup1)
    137.                     Me.Controls.Remove(DtgResult)
    138.                     Me.Controls.Remove(PnlDataGrid)
    139.                     Me.Update()
    140.             End Select
    141.  
    142.             Select Case Form_searchBy.Text
    143.                 Case "Art martial"
    144.                     Choice1 = "Cour1 = " & Searchbox1.text & " OR Cour2 = " & Searchbox1.text & " OR Cour3 = " & Searchbox1.text
    145.                 Case "Nom"
    146.                     Choice1 = Searchbox1.text
    147.                     Choice2 = Searchbox2.text
    148.                 Case "Dojo"
    149.                     Choice1 = Searchbox1.text
    150.                 Case "Degré"
    151.                     Choice1 = Searchbox1.text
    152.                 Case "Date de renouvellement"
    153.                     Choice1 = Searchbox1.text
    154.                 Case Else
    155.                     MsgBox("Le choix que vous avez entré dans la boîte de recherche est invalide")
    156.                     ClearCheck(Me.TopLevelControl)
    157.                     Me.Controls.Remove(DtgResult)
    158.                     Me.Controls.Remove(PnlDataGrid)
    159.                     Me.Update()
    160.             End Select
    161.  
    162.  
    163.         ElseIf Not Me.Form_searchBy.Text Is "" Then
    164.             Select Case Form_searchBy.Text
    165.                 Case "Art martial"
    166.                     Choice1 = "Cour1 = '" & Searchbox1.text & "' OR Cour2 = '" & Searchbox1.text & "' OR Cour3 = '" & Searchbox1.text & "'"
    167.                 Case "Nom"
    168.                     Choice1 = Searchbox1.text
    169.                     Choice2 = Searchbox2.text
    170.                 Case "Dojo"
    171.                     Choice1 = Searchbox1.text
    172.                 Case "Degré"
    173.                     Choice1 = Searchbox1.text
    174.                 Case "Date de renouvellement"
    175.                     Choice1 = Searchbox1.text
    176.                 Case Else
    177.                     MsgBox("Le choix que vous avez entré dans la boîte de recherche est invalide")
    178.                     ClearCheck(Me.TopLevelControl)
    179.  
    180.             End Select
    181.  
    182.         Else
    183.             MsgBox("Vous devez sélectionner au moins un critère de recherche")
    184.         End If
    185.  
    186.         Dim SQLString As String = "SELECT N°,Nom, Prenom, Cour1, Cour2, Cour3, ArtGrade, Lieu, DateRenouvellement  from " & DSTable & " WHERE " & Choice1 ' fetch data from the DB
    187.         Dim dsReturn As DataSet = DataModule.DBDataAcess(SQLString, DSTable)
    188.         DataModule.DBDataAcess(SQLString, DSTable)
    189.  
    190.         With DtgResult ' Populate the DataGridView From the returned DataSet
    191.             .DataSource = dsReturn.Tables(0)
    192.             .Update()
    193.             .Refresh()
    194.  
    195.         End With
    196.  
    197.     End Sub
    198.  
    199.     Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
    200.         ClearCheck(Me.TopLevelControl) 'reset the form
    201.     End Sub
    202.  
    203.     Private Sub DtgResult_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DtgResult.CellMouseDoubleClick
    204.  
    205.         ' Open the detailed view of the selected row on doubleclick event
    206.         Dim invId As Object = DtgResult.Rows(e.RowIndex).Cells(0).Value
    207.         Profil_Etudiant.DSEleve = Convert.ToString(invId)
    208.         Profil_Etudiant.Show()
    209.     End Sub
    210. End Class
    I am not here only to get answers, I am here to learn and to help!

    If you found this post helpful, let other people know I can help:
    <- Click the scales to the left and rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width