Results 1 to 10 of 10

Thread: [2005] I want to do somthing when I select the DataGridView ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Question [2005] I want to do somthing when I select the DataGridView ?

    I want to do somthing when I select the DataGridView
    I tried this but didn't succeed
    vb Code:
    1. If Me.DataGridView1.Select Then ' do somthing
    Last edited by nader; Nov 22nd, 2008 at 08:34 AM.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] I want to do somthing when I select the DataGridView ?

    Code:
        Private Sub DataGridView1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Enter
            Stop
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] I want to do somthing when I select the DataGridView ?

    I'm sorry I wasn't very clear.
    I have tow DataGridview. I want if DataGridview1 is selected will do somthing like print DataGridview1 and if DataGridview2 selected will not selected DataGridview1 and print DataGridview2.

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

    Re: [2005] I want to do somthing when I select the DataGridView ?

    First up, Select is a method, not a property, and it doesn't return any value, so you can't test IF it is True. You call the Select method to set focus to a specific control.

    Now, you're going to have to be much more clear about what it is you want. Are you saying that any time the first grid receives focus that you want to print the contents of the second grid? Surely not. What if the user hits the Tab key a few times to get to a specific control and focus happens to pass through this grid? Surely you wouldn't want to print the second grid then.

    Please, a full and clear description of what you want and why. Only if we have the full story can we be sure to provide the best solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] I want to do somthing when I select the DataGridView ?

    I have a code for print DGV and I have four DGV on same form I want to use the same code for print all the DGV individulay..it's mean
    If the DGV1 focused will only print it if DGV2 focused will only print it and so...

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] I want to do somthing when I select the DataGridView ?

    In that case test the ActiveControl property of the form:
    vb.net Code:
    1. If Me.ActiveControl Is Me.DataGridView1 Then
    2.     'Print DGV1.
    3. Else If Me.ActiveControl Is Me.DataGridView2 Then
    and so on.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] I want to do somthing when I select the DataGridView ?

    didn't executed the code
    vb Code:
    1. If Me.ActiveControl Is Me.DataGridView1 Then
    2.             MsgBox("DGV1")
    3.         End If

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

    Re: [2005] I want to do somthing when I select the DataGridView ?

    Where exactly are you executing that code? Let me guess: the Click event of a Button, correct? If so then the Button is going to be the ActiveControl. This sort of thing falss under the "full and clear description" category. As I said, if you don't provide us with a FULL and CLEAR description of the problem then we have to assume, i.e. guess, certain things. If we guess wrong it's not our fault.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: [2005] I want to do somthing when I select the DataGridView ?

    Here is the code I tried a CheckBoxes to define the options.
    vb Code:
    1. Private Function SetupThePrinting() As Boolean
    2.         If Me.CheckBox18.Checked = False And Me.CheckBox19.Checked = False And Me.CheckBox20.Checked = False And Me.CheckBox21.Checked = False Then Exit Function
    3.         Dim MyPrintDialog As PrintDialog = New PrintDialog()
    4.  
    5.         MyPrintDialog.AllowCurrentPage = False
    6.         MyPrintDialog.AllowPrintToFile = False
    7.         MyPrintDialog.AllowSelection = False
    8.         MyPrintDialog.AllowSomePages = True
    9.         MyPrintDialog.PrintToFile = False
    10.         MyPrintDialog.ShowHelp = False
    11.         MyPrintDialog.ShowNetwork = False
    12.  
    13.         If MyPrintDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return False
    14.  
    15.         PrintDocument1.DocumentName = "Customers Report"
    16.         PrintDocument1.PrinterSettings = MyPrintDialog.PrinterSettings
    17.         PrintDocument1.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings
    18.  
    19.         If Me.CheckBox18.Checked = True Then
    20.             Me.DataGridView1.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
    21.             Me.DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.White
    22.  
    23.             Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
    24.             Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = FontBold
    25.  
    26.             'Dim FontSize As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font.Size, 20)
    27.             'Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = FontSize
    28.  
    29.  
    30.             If MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
    31.  
    32.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView1, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    33.             Else
    34.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView1, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    35.             End If
    36.  
    37.         End If
    38.         If Me.CheckBox19.Checked = True Then
    39.             Me.DataGridView2.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
    40.             Me.DataGridView2.ColumnHeadersDefaultCellStyle.BackColor = Color.White
    41.  
    42.             Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
    43.             Me.DataGridView2.ColumnHeadersDefaultCellStyle.Font = FontBold
    44.  
    45.            
    46.             If MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
    47.  
    48.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView2, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    49.             Else
    50.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView2, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
    51.             End If
    52.  
    53.         End If
    54.         If Me.CheckBox20.Checked = True Then
    55.             Me.DataGridView4.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
    56.             Me.DataGridView4.ColumnHeadersDefaultCellStyle.BackColor = Color.White
    57.  
    58.             Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
    59.             Me.DataGridView4.ColumnHeadersDefaultCellStyle.Font = FontBold
    60.  
    61.        
    62.             If MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
    63.  
    64.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView4, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
    65.             Else
    66.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView4, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
    67.             End If
    68.  
    69.         End If
    70.         If Me.CheckBox21.Checked = True Then
    71.             Me.DataGridView3.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
    72.             Me.DataGridView3.ColumnHeadersDefaultCellStyle.BackColor = Color.White
    73.  
    74.             Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
    75.             Me.DataGridView3.ColumnHeadersDefaultCellStyle.Font = FontBold
    76.  
    77.            
    78.  
    79.  
    80.             If MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
    81.  
    82.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView3, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
    83.             Else
    84.                 DataGridView1Printer = New DataGridViewPrinter(DataGridView3, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
    85.             End If
    86.  
    87.         End If
    88.  
    89.  
    90.         Return True
    91.     End Function

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] I want to do somthing when I select the DataGridView ?

    OK, that last post contains code that you've not used previously yet you haven't told us what the current situation is. What happens when you execute that code. I'm getting tired of asking for you to explain over and over. This will be the last time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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