Friday, November 13, 2009

How to Display/Hide Crystal Report Viewer Tab and Status Bar at run time using VB.NET

How to Display/Hide Crystal Report Viewer Tab and Status Bar at run time using VB.NET


I am working with Visual Studio 2005 and faced some issues while working with crystal report, my requirement is to display and hide tab and status bar control from crystal report viewer, event tab control should display customized name in the tab text. I found the way to do this, below the code in vb.net

Display/Hide crystal report viewer tab control and rename the tab control


''' <summary>

''' This method will make tab controls visibile True/False

''' </summary>

''' <remarks>Ritesh</remarks>

Private Sub CrystalReportViewerTab(ByVal rptViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer, ByVal isVisible As Boolean)

Dim reportTabs As TabControl = rptViewer.Controls(0).Controls(0)

'if tab visible

If isVisible Then
With reportTabs

.ItemSize = New Size(70, 18)

.SizeMode = TabSizeMode.FillToRight

.Appearance = TabAppearance.Normal

'Here you can give customize name to tab

.TabPages(0).Text = "My Tab Text"

End With

Else 'if tab hide

With reportTabs

.ItemSize = New Size(0, 1)

.SizeMode = TabSizeMode.Fixed

.Appearance = TabAppearance.Buttons

End With

End If

End Sub

Display/Hide crystal report viewer status bar


''' This method will make status bar visibile True/False

Public Sub CrystalReportViewerStatusBar(ByVal rptViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer, ByVal isVisible As Boolean)

Dim ctl As Control

For Each ctl In rptViewer.Controls

If ctl.GetType().Name.ToString() = "StatusBar" Then

ctl.Visible = isVisible

End If

Next

End Sub

Wednesday, November 11, 2009

Datagridview CellDoubleClick event not getting fires with Datagridview drag drop functionality in VB.NET Window form

Differentiate between DataGridView Mousedown and CellDoubleclick events

OR

Datagridview CellDoubleClick event not getting fires with Datagridview drag drop functionality in VB.NET Window form


Problem


In VB.NET with Visual Studio 2005 I face a problem with working Datagridview drag and drop functionality. When I write a code to implement drag and drop functionality in Datagridview MouseDown event

Ex: DataGridView1.DoDragDrop(Index, DragDropEffects.Move)


And trying to fire CellDoubleClick event for same datagrid then this event is not getting fire, problem is when you do double click then first MouseDown event will fire then CelldoubleClick, but if control goes to MouseDown event then this line of code "DataGridView1.DoDragDrop(Index, DragDropEffects.Move)" canel CellDoubleClick event and CellDoubleClick event not getting fire.


Solution


To work with Both events togather we have to differenciate this by "Clicks" property in MouseDown event

Ex:

Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown


' 'Clicks' property can be used to solve this issue

If e.Clicks = 1 Then

' Write Code for Single Click

Else

'Write code for Double Click

End If

End Sub


Source code


So finally cell double and drag drop code should be like below


Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown


'Get the Index of Row which is being Dragged

'We would use this Index on Drop to identify which Row was dragged and get the values from that row

Dim Index As Integer

If e.Button = Windows.Forms.MouseButtons.Left Then

Index = DataGridView1.HitTest(e.X, e.Y).RowIndex

If e.Clicks = 1 Then ' For Single Click

If Index > -1 Then

'Pass the Index as "Data" argument of the DoDragDrop 'Function,

'Instead of Index as "Data" we can pass some data like 'array, object or images,

'That can be collected DataGridView2_DragOve event like

'e.Data.GetData(GetType(System.String))

DataGridView1.DoDragDrop(Index, DragDropEffects.Move)

End If

End If

End If

End Sub


Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

MessageBox.Show("DGV1_CellDoubleClick")

End Sub


Private Sub DataGridView2_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView2.DragOver

e.Effect = DragDropEffects.Move

End Sub


Private Sub DataGridView2_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView2.DragDrop

'Write your code do operation in DataGridView2

End Sub

How to implements Drag Drop functionality with DataGridView : click here

Thursday, November 05, 2009

How to write SQL query to generate XML string, How to get XML as an output parameter from stored procedure

How to write SQL query to generate XML string, How to get XML as an output parameter from stored procedure

You can very well write SQL query to generate XML string or write stored procedure to give output as XML string

For Oracle Database
1) http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb13gen.
htm#i1029599

For Microsoft SQL Server Database
1) http://msdn.microsoft.com/en-us/library/ms345137(SQL.90).aspx

Monday, November 02, 2009

Problem to display date in the MaskedTextBoxControl in dotnet

 

When you try to display date value to MaskedTextBox then it show different date in the field especially when you have single digit on the date. Even though MaskedTextBox control "Mask" property set it to "00/00/0000".

 

When you try to assign the date into this field like:

 

Problem

 

MaskTextBox.Text = "1/12/2009", it will display in the field like "11/22/009_"

 

Solution

 

To overcome this issue you have to send your date with proper format like below

 

MaskedTextBox.Text = Format(Convert.ToDateTime("1/12/2009 5:58:00 PM"), "MM/dd/yyyy")

OR

MaskedTextBox.Text = Format(Convert.ToDateTime(Date.Now), "MM/dd/yyyy")

 

Now it will display in the field as a correct date format "1/12/2009".