Saturday, February 2, 2013

HOW TO GET THE SELECTED ITEM(S) IN A LIST VIEW CONTROL


HOW TO GET THE SELECTED ITEM(S) IN A LIST VIEW CONTROL

ListView returns collections of selected items and indices through the SelectedItems and SelectedIndices properties. Note that these collections are empty, if no item is currently selected
(lst.SelectedItems.Count == 0).

The first item that is selected is

lst.SelectedItems[0]

The index of this item in the Items collection is

lst.SelectedIndices[0].

So basically
 
lst.SelectedItems[0]
 
is the same as

lst.Items[lst.SelectedIndices[0]]
 
 
You can also use check boxes. Set CheckBoxes to true for this. Through the CheckedItems and CheckedIndices properties you can see which items are checked.

KEYPRESS EVENT IN VB.NET


Handle Keyboard Input at the Form Level in VB.NET
Windows Forms processes keyboard input by raising keyboard events in response to Windows messages. Most Windows Forms programs process keyboard input by handling the keyboard events.

How do I detect keys pressed in VB.NET
You can detect most physical key presses by handling the KeyDown or KeyUp events. Key events occur in the following order:

  KeyDown
  KeyPress
KeyUp

How to detect when the Enter Key Pressed in VB.NET
The following VB.NET code behind creates the KeyDown event handler. If the key that is pressed is the Enter key, a MessegeBox will displayed .

  If e.KeyCode = Keys.Enter Then
 MsgBox("enter key pressd ")
End If

How to get TextBox1_KeyDown event in your VB.Net source file ?
Select your VB.Net source code view in Visual Studio and select TextBox1 from the top-left Combobox and select KeyDown from top-right combobox , then you will get keydown event sub-routine in your source code editor.

  Private Sub TextBox1_KeyDown(...)..
End Sub

vb-key-down
The following VB.NET source code shows how to capture Enter KeyDown event from a TextBox Control.

How to: Print a Form by Using the PrintForm Component (Visual Basic)

Visual Studio 2012
4 out of 4 rated this helpful - Rate this topic

The PrintForm component enables you to quickly print an image of a form exactly as it appears on screen without using a PrintDocument component. The following procedures show how to print a form to a printer, to a print preview window, and to an Encapsulated PostScript file.

To print a form to the default printer

  1. In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
    The PrintForm component is added to the component tray.
  2. In the Properties window, set the PrintAction property to PrintToPrinter.
  3. Add the following code in the appropriate event handler (for example, in the Click event handler for a Print Button).
    PrintForm1.Print()
    

To display a form in a print preview window

  1. In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
    The PrintForm component is added to the component tray.
  2. In the Properties window, set the PrintAction property to PrintToPreview.
  3. Add the following code in the appropriate event handler (for example, in the Click event handler for a Print Button).
    PrintForm1.Print()
    

To print a form to a file

  1. In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
    The PrintForm component is added to the component tray.
  2. In the Properties window, set the PrintAction property to PrintToFile.
  3. Optionally, select the PrintFileName property and type the full path and file name for the destination file.
    If you skip this step, the user will be prompted for a file name at run time.
  4. Add the following code in the appropriate event handler (for example, in the Click event handler for a Print Button).
    PrintForm1.Print() 
     
     
     
    Ref: http://msdn.microsoft.com/en-us/library/bb629268.aspx