|
-
Nov 22nd, 2008, 08:29 AM
#1
Thread Starter
Fanatic Member
[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:
If Me.DataGridView1.Select Then ' do somthing
Last edited by nader; Nov 22nd, 2008 at 08:34 AM.
-
Nov 22nd, 2008, 09:16 AM
#2
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
-
Nov 22nd, 2008, 10:21 AM
#3
Thread Starter
Fanatic Member
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.
-
Nov 22nd, 2008, 08:20 PM
#4
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.
-
Nov 22nd, 2008, 09:49 PM
#5
Thread Starter
Fanatic Member
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...
-
Nov 22nd, 2008, 10:52 PM
#6
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:
If Me.ActiveControl Is Me.DataGridView1 Then 'Print DGV1. Else If Me.ActiveControl Is Me.DataGridView2 Then
and so on.
-
Nov 23rd, 2008, 01:37 AM
#7
Thread Starter
Fanatic Member
Re: [2005] I want to do somthing when I select the DataGridView ?
didn't executed the code
vb Code:
If Me.ActiveControl Is Me.DataGridView1 Then
MsgBox("DGV1")
End If
-
Nov 23rd, 2008, 02:45 AM
#8
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.
-
Nov 23rd, 2008, 01:16 PM
#9
Thread Starter
Fanatic Member
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:
Private Function SetupThePrinting() As Boolean
If Me.CheckBox18.Checked = False And Me.CheckBox19.Checked = False And Me.CheckBox20.Checked = False And Me.CheckBox21.Checked = False Then Exit Function
Dim MyPrintDialog As PrintDialog = New PrintDialog()
MyPrintDialog.AllowCurrentPage = False
MyPrintDialog.AllowPrintToFile = False
MyPrintDialog.AllowSelection = False
MyPrintDialog.AllowSomePages = True
MyPrintDialog.PrintToFile = False
MyPrintDialog.ShowHelp = False
MyPrintDialog.ShowNetwork = False
If MyPrintDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return False
PrintDocument1.DocumentName = "Customers Report"
PrintDocument1.PrinterSettings = MyPrintDialog.PrinterSettings
PrintDocument1.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings
If Me.CheckBox18.Checked = True Then
Me.DataGridView1.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
Me.DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.White
Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = FontBold
'Dim FontSize As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font.Size, 20)
'Me.DataGridView1.ColumnHeadersDefaultCellStyle.Font = FontSize
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
DataGridView1Printer = New DataGridViewPrinter(DataGridView1, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
Else
DataGridView1Printer = New DataGridViewPrinter(DataGridView1, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
End If
End If
If Me.CheckBox19.Checked = True Then
Me.DataGridView2.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
Me.DataGridView2.ColumnHeadersDefaultCellStyle.BackColor = Color.White
Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
Me.DataGridView2.ColumnHeadersDefaultCellStyle.Font = FontBold
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
DataGridView1Printer = New DataGridViewPrinter(DataGridView2, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
Else
DataGridView1Printer = New DataGridViewPrinter(DataGridView2, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, True)
End If
End If
If Me.CheckBox20.Checked = True Then
Me.DataGridView4.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
Me.DataGridView4.ColumnHeadersDefaultCellStyle.BackColor = Color.White
Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
Me.DataGridView4.ColumnHeadersDefaultCellStyle.Font = FontBold
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
DataGridView1Printer = New DataGridViewPrinter(DataGridView4, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
Else
DataGridView1Printer = New DataGridViewPrinter(DataGridView4, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
End If
End If
If Me.CheckBox21.Checked = True Then
Me.DataGridView3.EnableHeadersVisualStyles = False 'this line is neccesry to make the second line work.
Me.DataGridView3.ColumnHeadersDefaultCellStyle.BackColor = Color.White
Dim FontBold As New Font(DataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold)
Me.DataGridView3.ColumnHeadersDefaultCellStyle.Font = FontBold
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
DataGridView1Printer = New DataGridViewPrinter(DataGridView3, PrintDocument1, True, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
Else
DataGridView1Printer = New DataGridViewPrinter(DataGridView3, PrintDocument1, False, True, Form6.RichTextBox1.Text, New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Point), Color.Black, True)
End If
End If
Return True
End Function
-
Nov 23rd, 2008, 05:21 PM
#10
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|