Archive for the ‘Controls’ Category

A Generic error occured in GDI+

Source Control:
If this exception occurred in DataGrid Control, check if the displayed data is large. This might be the caused of the exception.

, ,

No Comments


How to get Last Directory of OpenDialog box in .net

You can use the InitialDirectory property of the dialog box to get the last directory browsed.

, , ,

No Comments


How to Select Records in the Datatable

To select records/items in the datatable;

  1.  
  2. Sub FilterData(dt as DataTable)
  3. Dim dRow() as Datarow
  4.  
  5. dRow = dt.select("CustomerID=10" )
  6.  
  7. Console.WriteLine("Rows " & dRow.Length)
  8.  
  9.  
  10. End Sub

, , ,

No Comments


How to change the Height of Listbox Item

To change the height of the listbox items you have to customize the listbox by drawing the each item manually, to do this;

  1. Select Listbox control, in the property set the DrawMode to OwnerDrawVariable
  2. In MeasureItem event of the listbox, add the code below

    e.ItemHeight = 25

  3. Add this code to the DrawItem Event
    1.     Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
    2.         e.DrawBackground()
    3.  
    4.         Dim drawbrush As Brush
    5.  
    6.         If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
    7.             drawbrush = Brushes.White
    8.         Else
    9.             drawbrush = Brushes.Black
    10.         End If
    11.  
    12.         Dim s As String
    13.  
    14.         s = CType(sender, ListBox).Items(e.Index).ToString
    15.  
    16.         e.Graphics.DrawString(s, CType(sender, Control).Font, drawbrush, e.Bounds.X, e.Bounds.Y)
    17.  
    18.  
    19.     End Sub

Note: The difference between the two owner-drawn options is that with fixed drawing each item in the list is the standard size (typically 13 px), and with OwnerDrawVariable you can specify the height for each item independently.

, , ,

No Comments


Conversion from type ‘DataRowView’ to type ‘Integer’ is not valid.

Conversion from type ‘DataRowView’ to type ‘Integer’ is not valid this will occur during binding the combo box by setting the datasource and you have a code to execute inside the combobox_SelectedIndexChanged Event that retrieves the selected value of the combo box.  The below script will give you  an exception error at the time of setting the datasource of the combobox

Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDemographics.SelectedIndexChanged

Messagebox.show(cboDemographics.SelectedValue)

End Sub

to correct this you have to check the selectedValue

Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDemographics.SelectedIndexChanged

If TypeOf cboDemographics.SelectedValue Is DataRowView Then
Exit Sub
End If
Messagebox.show(cboDemographics.SelectedValue)

End Sub

, ,

4 Comments


How to Select item in combobox by value

How to Select item in combobox by value

Private sub ComboBoxSelect(value as string)

combobox1.SelectedValue = value

End Private

,

No Comments



SetPageWidth