Monday, November 3, 2008

Handling Keystrokes in DataGridView

Private Sub dgv_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgv.EditingControlShowing
 
If Me.dgv.CurrentCell.ColumnIndex = 0 And Not e.Control Is Nothing Then
    Dim tb As TextBox = CType(e.Control, TextBox)
    AddHandler tb.KeyDown, AddressOf TextBox_KeyDown
    AddHandler tb.KeyPress, AddressOf TextBox_KeyPress
End If

 
End Sub
 

Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
 If  e.KeyCode = Keys.Space Then
     flag = True
 End If

End Sub
 
Private Sub TextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
 e.Handled = flag
 flag = False

End Sub

Export SQL table to excel

Dim excel As New Excel.Application
        Dim wBook As Excel.Workbook
        Dim wSheet As Excel.Worksheet

        wBook = excel.Workbooks.Add()
        wSheet = wBook.ActiveSheet()

        Dim dt As DataGridView = TblJobMethodsDataGridView.DataSource.Tables(0)
        Dim dc As System.Data.DataColumn
        Dim dr As System.Data.DataRow
        Dim colIndex As Integer = 0
        Dim rowIndex As Integer = 0

        For Each dc In dt.Columns
            colIndex = colIndex + 1
            excel.Cells(1, colIndex) = dc.ColumnName
        Next

        For Each dr In dt.Rows
            rowIndex = rowIndex + 1
            colIndex = 0
            For Each dc In dt.Columns
                colIndex = colIndex + 1
                excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)

            Next
        Next

        wSheet.Columns.AutoFit()
        Dim strFileName As String = "D:\ss.xls"
        Dim blnFileOpen As Boolean = False
        Try
            Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(strFileName)
            fileTemp.Close()
        Catch ex As Exception
            blnFileOpen = False
        End Try

        If System.IO.File.Exists(strFileName) Then
            System.IO.File.Delete(strFileName)
        End If

        wBook.SaveAs(strFileName)
        excel.Workbooks.Open(strFileName)
        excel.Visible = True

Friday, August 29, 2008

youtube videos download


just copy poste the youtube url address into the textbox
and press download button. video should be save by default name in the hard disk and rename later on. (also play associated the video in the youtube.com).
Very useful.
download from the following link:-

http://s2.orbitfiles.com/index.php?link=3232725130&sid=6fc5f8f8b300bfe120252bca16ec1fad&force=1

Wednesday, August 27, 2008

vb2008: using LinQ

I have now set up a console app to test this piece of code using Northwind as follows:-
Imports System.Data.LinqModule Module1
Sub Main() Dim db As New NorthWindDataContext
Dim Emps = From Employee In db.Employees _ Select Employee
Debug.Print(Emps.Count)
For Each emp In Emps

Console.WriteLine("Code={0}, Name={1}", emp.EmployeeID, emp.FirstName) Next
Console.ReadLine() End Sub
End Module

vb2008: Unable to debug: The binding handle is invalid


Unable to debug: The binding handle is invalid


Open the project properties, Debug, Disable -> "Enable the Visual Studio hosting process"


vb2008: how to retrieve the desktop display settings

use the following code:-

Dim MyScreenSize As New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)

Monday, July 28, 2008