Pages

Sunday, 17 October 2010

How to set AutoComplete for Textbox in VB.net

Ever wondered how to set up auto complete for Textbox and Combo box in VB.net.  In Windows Form 2.0 and higher, some of the controls support this feature including the combo box and textbox controls. By using these feature, we can easily build auto completion functionality and here is the sample code for text box control

 

Dim Companies As AutoCompleteStringCollection
Companies = New AutoCompleteStringCollection
Companies.Add(“Ferrari”)

Companies.Add(“Ferrari2”)
txtAuto.AutoCompleteMode = AutoCompleteMode.Suggest
txtAuto.AutoCompleteSource = AutoCompleteSource.CustomSource
txtAuto.AutoCompleteCustomSource = Companies

Simple and very useful end user experience…

Thursday, 19 August 2010

How to register Hot Keys in VB.net

Code sample: Register multiple hotkeys such as Alt+D, Alt+C, etc.

Imports System.Runtime.InteropServices

Public Class Form1

Public Const MOD_ALT As Integer = &H1 'Alt key
Public Const WM_HOTKEY As Integer = &H312

<DllImport("User32.dll")> _
Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _
ByVal id As Integer, ByVal fsModifiers As Integer, _
ByVal vk As Integer) As Integer
End Function

<DllImport("User32.dll")> _
Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _
ByVal id As Integer) As Integer
End Function

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle, 100, MOD_ALT, Keys.D)
RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.C)
End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
Dim id As IntPtr = m.WParam
Select Case (id.ToString)
Case "100"
MessageBox.Show("You pressed ALT+D key combination")
Case "200"
MessageBox.Show("You pressed ALT+C key combination")
End Select
End If
MyBase.WndProc(m)
End Sub

Private Sub Form1_FormClosing(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles MyBase.FormClosing
UnregisterHotKey(Me.Handle, 100)
UnregisterHotKey(Me.Handle, 200)
End Sub

End Class

Thursday, 5 August 2010

"HTTP Error 404 - File or Directory not found" error message when you request dynamic content with IIS 6.0

To permit IIS to serve dynamic content, the administrator must unlock this content in the Web service extensions node in IIS Manager. To do this, the administrator must either enable a pre-existing Web service extension or add a new Web service extension.

Enable a Pre-existing Web Service Extension in IIS 6.0

To permit IIS to serve content that requires a specific ISAPI or CGI extension that is already listed in the Web service extensions list, follow these steps:

  1. Open IIS Manager, expand the master server node (that is, the Servername node), and then select the Web service extensions node.
  2. In the right pane of IIS Manager, right-click the extension that you want to enable. In this example, this is Active Server Pages.
  3. Click to select the Allow check box.

Add a New Web Service Extension to IIS 6.0

To permit IIS to serve content that requires a specific ISAPI or CGI extension that is not already listed in the Web service extensions list, follow these steps:

  1. Open IIS Manager, expand the master server node, and then select the Web service extensions node.
  2. In the right pane of the IIS Manager, click Add a new Web service extension under Tasks.
  3. In the Extension name box, type a friendly name for the extension that you want to add (for example, FrontPage Server Extensions).
  4. In the Required files box, click Add, and then select the path and the name of the file that will handle requests for the specific extension. After you select the path and the file name, click OK.
  5. If the extension must be enabled immediately, click to select the Set extension status to allowed check box.
  6. Click OK to save your changes.

For more information, please refer to http://support.microsoft.com/kb/315122

Tuesday, 29 June 2010

How to view line numbers in VB.NET

Remember line numbers ??? Long time ago, they were used to branch them with a ‘Go To’ statement. And it is still available with Visual Studio 2008 and pretty useful for error handling too…

For example, a lot of error messages give you specific line numbers in your code to use to find the errors. Trying to count down the page manually can be pretty tedious.

To enable line numbers, go to

Tools menu item > Options > Text Editor > Basic > General

Click the checkbox in front of "Line Numbers". It should do it…