Visual Basic .NET Samples

Protect Your .NET application - Skater .NET Obfuscator 4.80

  • Convert Excel spreadsheet to PDF in .NET application
  • DataGridView Combo column (extended combobox)
  • DataGridView Numeric Column
  • .Net DataGrid combobox. Auto-fill and Dictionary.
  • Auto-fill combo box
  • .Net DataGrid Simple Sample.
  • Remove duplicates from an array
  • .Net XP DataGrid Button column Style.
  • .Net DataGrid Memo column Style.
  • .Net DataGrid DateTimePicker column Style.
  • How to Trap the Tab Key in a .NET Control?
  • How to format a datagrid column using a Date/Time format? How to update data in the column?
  • How to format a datagrid column using a Numeric format? How to update data in the column?
  • How to mask the data in a DataGrid Data column? How to mask the phone number (SSN, IP address) data?
  • How to draw a line in .NET? Line Control for .NET
  • Skater .NET Obfuscator
    More about Skater .NET Obfuscator
    Download Skater .NET Obfuscator
    Order Skater .NET Obfuscator

    DataGridColumns .NET assembly (Forms)
    More about DataGridColumns.dll
    Download DataGridColumns.dll
    Order DataGridColumns.dll

    Export To PDF .NET assembly
    More about ExportToPDF.dll
    Download ExportToPDF assembly
    Order ExportToPDF .NET assembly

    XML Converter is available!
    More about XML Converter
    Download XML Converter
    Order XML Converter

    Controls .NET assembly (WinForms)
    More about Rustemsoft LLC.Controls.dll
    Download Rustemsoft LLC.Controls.dll
    Order Rustemsoft LLC.Controls.dll


    Convert Excel spreadsheet to PDF in .NET application Download VB.NET and C# samples

    For Excel to PDF .NET conversion task you can transform by one spreadsheet in Excel file only. You have to specify the spreadsheet name by assigning value of SourceTableSheetName property. Also you can setup XlsConvertMode property to define what a type of Excel to PDF conversion you would like to implement.
    The property takes two conversion mode value.
    Fast - MS Excel spreadsheets will be transformed much faster. However this way is good if you have homogeneous (similar) data for each MS Excel sheet column. If you have different data types stored in the same column please do not select this option.
    Detailed - MS Excel spreadsheets will be transformed slowly. However this way is good if you have heterogeneous (different) data types values (numbers, date or text) stored together in some MS Excel spreadsheets field. Conversion to PDF will not lose this motley data.
    allowExcelHeaders property is useful to define if the spreadsheet?s column titles will be specified as column headers within generated PDF output file or not.

    VB .NET

    Imports Rustemsoft LLC.ExportToPDF

    ...

    ' Define new ExportToPDF.Export class object
    Dim ExportToPDFobject As New Rustemsoft LLC.ExportToPDF.Export

    ' Define SourceType property as Excel
    ExportToPDFobject.SourceType = SourceTypes.Excel
    ' Specify Excel conversion mode as Detailed
    ExportToPDFobject.XlsConvertMode = XlsConvertModes.Detailed
    ' Define that first row of spreadsheet is column headers on PDF document
    ExportToPDFobject.FirstRowIsHeaders = True
    ' Specify spreadsheet name within your Excel file that will be converted to PDF
    ExportToPDFobject.SourceTableSheetName = "Sheet1"
    ' Specify data source file location
    ExportToPDFobject.inputFileName = "C:\MyDirectory\MyExcel.xls"
    ' Specify PDF output file path
    ExportToPDFobject.outputFileName = "C:\MyDirectory\My.pdf"

    ' Assign ExportToPDFobject's properties
    ' Specify grid appearance on PDF
    ExportToPDFobject.grid = True
    ExportToPDFobject.gridWidth = 0.1
    ExportToPDFobject.gridColor = Color.Gray

    ' Specify PDF document text font, size, and color
    ExportToPDFobject.font = pdfFont.Helvetica
    ExportToPDFobject.fontSize = 1
    ExportToPDFobject.textColor = Color.Black

    ' Define columns headers' specific properties
    ExportToPDFobject.HeadersOnEachPage = True
    ExportToPDFobject.HeadersFont = pdfFont.Helvetica_BoldOblique
    ExportToPDFobject.HeadersTextColor = Color.Red

    ' Specify PDF document title text, font, size, and color
    ExportToPDFobject.Title = "Title"
    ExportToPDFobject.TitleFont = pdfFont.Times_Roman
    ExportToPDFobject.TitleFontSize = 5
    ExportToPDFobject.TitleColor = Color.Green

    ' Specify PDF document footer text, font, size, and color
    ExportToPDFobject.Footer = "Footer"
    ExportToPDFobject.FooterFont = pdfFont.Times_Roman
    ExportToPDFobject.FooterFontSize = 5
    ExportToPDFobject.FooterColor = Color.Brown

    ' Specify PDF document layout properties
    ExportToPDFobject.pageMarginLeft = 20
    ExportToPDFobject.pageMarginRight = 10
    ExportToPDFobject.pageMarginTop = 50
    ExportToPDFobject.pageMarginBottom = 50
    ExportToPDFobject.pageWidth = 0
    ExportToPDFobject.pageHeight = 0
    ExportToPDFobject.pageLinesCount = 0
    ExportToPDFobject.Landscape = False

    ' Run conversion to PDF
    ExportToPDFobject.Convert()


    .Net DataGrid combobox. Auto-fill and Dictionary. Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    This sample introduces how to add a DataGridColumnStyle that contains combobox to a DataGrid on your .Net form. It is not just a dropdown combobox, which appears when a datagrid cell becomes the current cell. This .Net DataGrid DataGridColumnStyle combobox control has the following attractive features:

    This combobox DataGridColumnStyle automatically fills the text at the cursor with the value of its dropdown values list. As characters are typed, the component finds the closest matching item from the list and automatically fills in the remaining characters. Appended characters are highlighted so that they are replaced by any further typing. For this auto-filling feature you can setup the character case sensibility.

    This DataGridColumnStyle gives you ability to instantly update dropdown values with a really simple and friendly user interface. When you click the additional dropdown button of the combo a dictionary of its list values will be displayed below the combo. You can update values, and insert and delete rows in the dictionary grid.

    The control gives an ability to get a nesting combo box that filters values from a related child table. In a dictionary grid, you can view and edit related data in a child table. In your database a Master table has a one-to-many relationship with a Child table; so for each row of the Master table in Dictionary grid, you or your customer can view and edit the related rows of the Child table in a dictionary grid.

    You can turn off all or some of these features and use the combobox DataGridColumnStyle just as an easy dropdown DataGrid combobox.

    You can set its DataSource, DisplayMember, and ValueMember to bind the combobox to a foreign table.

    Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    ' Set datagrid column styles
    With TableStyle.GridColumnStyles
    ' Set datagrid ColumnStyle for Car field
    .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("Car")))
    With .Item(0)
    .MappingName = "Car"
    .HeaderText = "Car Name"
    .Width = 130
    .NullText = String.Empty
    .ReadOnly = True
    End With

    ' Set datagrid ComboBox ColumnStyle for PubID field
    .Add(New DataGridComboBoxColumn(ds.Tables.Item("Companies"), 1, 0))
    ' Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    ' Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    With .Item(1)
    .MappingName = "PubID"
    .HeaderText = "Company ID"
    .Width = 200
    .NullText = String.Empty
    End With

    ' Set datagrid combobox ColumnStyle for State field
    .Add(New DataGridComboBoxColumn(ds.Tables.Item("States"), 0, 0, , , False))
    ' Datagrid ComboBox DisplayMember field has order number 0. Name of this column is "State"
    ' Datagrid ComboBox ValueMember field has order number 0. It is the same column like for DisplayMember
    With .Item(2)
    .MappingName = "State"
    .HeaderText = "State"
    .Width = 45
    .NullText = String.Empty
    End With

    ' Set datagrid XP Style Button ColumnStyle for City field
    .Add(New DataGridXPButtonColumn())
    ' Also you may set datagrid Button ColumnStyle for City
    ' field without XP Button Style as the following:
    ' .Add(New DataGridButtonColumn())
    With .Item(3)
    .MappingName = "City"
    .HeaderText = "City"
    .Width = 60
    .NullText = String.Empty
    End With

    ' Set datagrid Memo ColumnStyle for Comments field
    .Add(New DataGridMemoColumn("Car description"))
    With .Item(4)
    .MappingName = "Comments"
    .HeaderText = "Comments"
    .Width = 60
    .NullText = String.Empty
    End With
    End With

    Learn more about DataGridColumns assembly


    DataGridView Combo column (extended combobox) Download VB.NET and C# samples

    The DataGridViewComboColumn contains combobox for a DataGridView on your .NET form. The Combo column is not just a dropdown combobox, which appears when a DataGridView cell becomes the current cell. The .Net DataGridView Combo Column control has the following attractive features:

    This DataGridView Combo column is not just a dropdown combobox, which appears when a DataGridView cell becomes the current cell. This DataGridView Combo Column gives you ability to instantly update dropdown values with a really simple and friendly user interface. When you click the combo button a dropdown multiple columns grid of its list values will be shown below the combo. You can update values,and insert and delete rows into the dictionary DataGridView.

    You can set its DataSource, DisplayMember, and ValueMember to bind the Combo to a foreign table

    The control gives an ability to get a nesting combo box that filters values from a related child table. In a dictionary grid, you can view and edit related data in a child table. In your database a Master table has a one-to-many relationship with a Child table; so for each row of the Master table in Dictionary grid, you or your customer can view and edit the related


    rows of the Child table in a dictionary grid. For this case we have to define two string arrays with key fields' names MasterFields and ChildFields. To get the filtering we must identify Master and Child tables' key fields. These fields' names in both arrays must have the same order sequence.

    Syntax
    DataGridViewComboColumn()

    DataGridViewColumns .NET assembly
    More about DataGridView Columns
    Download DataGridViewColumns.dll
    Order DataGridView Columns dll

    Some Properties

    box - Combobox object in selected cell. Gets the hosted box control that is an overridden instance of the ComboBox control.

    box.DataSource - a source for DataGridView values list as System.Data.DataTable

    box.DisplayMember - field to display in combo as String (name of table column)

    box.ValueMember - field with values, which binds to combo as String (name of table column). Specify the contents of the ValueMember property in cases where you bind data.

    box.DisplayMode - Identifies what kind of data you would like to see in whole DataGridView customized column, as DataGridViewColumns.DisplayModes. You may choose the following values:
    ShowDisplayMember - default. DisplayMember will be shown in whole column
    ShowValueMember - ValueMember will be shown in whole column
    ShowValueMember_and_DisplayMember - ValueMember + DisplayMember will be shown together in a column

    box.allDictionaryColumns - The property identifies how many columns you need to see in the called Dictionary grid, as DataGridViewColumns.FieldsDisplayType(default is DisplayMember_ValueMember_only)
    You may set the following values:
    DisplayMember_ValueMember_only - default. DisplayMember and/or ValueMember fields will be shown in your drop-down Dictionary grid.
    allFields - all related child table's fields will be shown in your drop-down Dictionary grid.
    allFields_ExceptRelationKey - all related child table's fields will be shown in your Dictionary grid except relation key fields.

    Also you can leave the allDictionaryColumns parameter (define it as null in C# and C++ code) and specify your own columns for the Dictionary DataGridView. Please see our samples to learn how to do that.

    Example  
    The following example creates a DataGridViewComboColumn object and adds it to the DataGridView layout.  
     
    With DataGridView1  
     
    ' Set DataGridView Combo Column for CarID field   
    Dim ColumnCar As New DataGridViewComboColumn  
    ' DataGridView Combo ValueMember field has name "CarID"  
    ' DataGridView Combo DisplayMember field has name "Car"  
    With ColumnCar  
        .DataPropertyName = "CarID"  
        .HeaderText = "Car Name"  
        .Width = 80  
        ' Bind ColumnCar to Cars table  
        .box.DataSource = ds.Tables("Cars")  
        .box.ValueMember = "CarID"  
        .box.DisplayMember = "Car"  
    End With  
    .Columns.Add(ColumnCar)  
     
    End With  
     
    Please read the DataGridViewColumns assembly documentation to learn more about the DataGridViewComboColumn class provided events and class members.

    DataGridView Numeric Column Download VB.NET and C# samples

    This formatted intelligent NumericColumn control can mask the numbers, digits, decimal and checks the validation, and automatically set the delimiter location. You may input any number. If there is a numeric scale defined with the field, it is used to format the display and the input.

    Note By default the numeric column follows the formatting of the original column. If you define specific parameters (MaxLength, DecimalLength,...) for the column it will accept them. However if the original DataTable's column could not accept your defined parameters it will ignore your settings. For example, the datatype for an original numeric datatable's field is Integer and you give to the DecimalLength parameter some not zero value. For this case the control will not allow your users to insert decimal values. Please choose appropriate datatypes and column settings.

    Syntax
    DataGridViewNumericColumn()

    Some Properties

    box - Numeric textbox object in selected cell. Gets the hosted box control that is an overridden instance of the Numeric textbox control.

    box.IntegerOnly - as Boolean. Default is False.

    box.PositiveOnly - as Boolean. Default is False.

    box.DefaultValue - any numeric value. Default is empty numeric (null/Nothing).

    box.MinValue - any floating-point value range minimum of the inserted value. Default is empty numeric (null/Nothing).

    box.MaxValue - any floating-point value range maximum of the inserted value. Default is empty numeric (null/Nothing).

    box.MaxLength - as integer, specifies a fixed length of whole input area. Default is empty numeric (null/Nothing).

    box.DecimalLength - as integer, specifies a fixed decimal length. Default is empty numeric (null/Nothing).


    Example  
    The following example creates a DataGridViewNumericColumn and adds it into the DataGridView layout.  
    ' Set datagrid Numeric Column for Price field  
    Dim NumericColumn As New DataGridViewNumericColumn  
    With NumericColumn  
        .DataPropertyName = "Price"  
        .HeaderText = "Price"  
        .Width = 60  
        ' Define some Numeric Box specific properties  
        .box.DecimalLength = 2  
        .box.MaxLength = 10  
        .box.PositiveOnly = True  
        ' Identify column selected cell back and foreground colors  
        .box.BackColor = Color.LightGray  
        .box.ForeColor = Color.DarkRed  
        ' Define cell warning color  
        .box.ProblemColor = Color.LightPink  
        ' Identify whole column back and fore colors  
        .CellTemplate.Style.BackColor = Color.WhiteSmoke  
        .CellTemplate.Style.ForeColor = Color.Brown  
        .CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight  
        ' Define cell border style  
        .box.BorderStyle = BorderStyle.Fixed3D  
        ' Assign selected cell's font   
        .box.Font = New Font("Tahoma", 8, FontStyle.Bold)  
    End With  
    DataGridView1.Columns.Add(NumericColumn)  
     
    Please read the DataGridViewColumns assembly documentation to learn more about the DataGridViewNumericColumn class provided events and class members.

    Auto-fill combo box

    How to search a list box by typing text into a combobox control? This example shows how to implement an auto-fill combo box. You often faced it on some sophisticated web pages. As characters are typed, the program finds the closest matching item from the combobox list and automatically fills in the remaining characters. A similar approach using event "Change" can be used to work with a text box and list box control.


    Download this sample: VB .NET VB6

    Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ' Retrieve all the Company Names in the table
    Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
    Dim strConn As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source = " + AppPath + "Samples.mdb"
    Dim dbConn As System.Data.OleDb.OleDbConnection = _
    New System.Data.OleDb.OleDbConnection(strConn)

    dbConn.Open()
    Dim DSet As New DataSet, SQLStr As String
    Dim cmd As System.Data.OleDb.OleDbCommand
    Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter

    Dim tRow As DataRow, tTbl As DataTable
    With dbAdaptr
    .TableMappings.Add("Table", "Companies")
    SQLStr = "Select [Company Name] from Companies"
    cmd = New System.Data.OleDb.OleDbCommand(SQLStr, dbConn)
    cmd.CommandType = CommandType.Text
    .SelectCommand = cmd
    .Fill(DSet)
    .Dispose()
    End With

    DSet.AcceptChanges()
    tTbl = DSet.Tables.Item(0)
    DSet.Dispose()
    dbConn.Close()

    ' fill out array by Company Names for cboRightCombo combobox
    cboRightCombo.Text = ""
    cboRightCombo.Items.Clear()
    cboRightCombo.BeginUpdate()

    ' Load the Company Names into the ComboBox Control
    For Each tRow In tTbl.Rows
    cboRightCombo.Items.Add(tRow("Company Name").ToString)
    Next
    cboRightCombo.EndUpdate()
    End Sub

    ' Close application
    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles cmdClose.Click
    Me.Close()
    End Sub

    ' Use event "Change" for alphabetical search an appropriate
    ' value in combo box list and put it into combobox Text.
    Private Sub cboRightCombo_TextChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles cboRightCombo.TextChanged
    Dim boxIndex As Integer, lExst As Boolean
    Dim box As ComboBox = sender
    Dim txt As String = box.Text
    Dim posCursor As Integer = box.SelectionStart
    ' If Cursor does not stay on the beginning of text box.
    If posCursor <> 0 Then
    lExst = False
    ' Go in cycle through the combo box list to
    ' find the appropriate entry in the list
    For boxIndex = 0 To box.Items.Count - 1
    If UCase(Mid(box.Items(boxIndex), 1, posCursor)) = UCase(Mid(txt, 1, posCursor)) Then
    box.Text = box.Items(boxIndex)
    box.SelectionStart = posCursor
    lExst = True
    Exit For
    End If
    Next
    ' We didn't find appropriate entry and return previous value to text box
    If Not lExst Then
    box.Text = Mid(txt, 1, posCursor - 1) + Mid(txt, posCursor + 1)
    box.SelectionStart = posCursor - 1
    End If
    End If
    End Sub

    End Class

    Run the project and type some text into the combobox, and if it matches the text in the list of your combobox then the text will be displayed in the combobox.

    Remove duplicates from an array

    How to remove the duplicates in a string array? Here is an example of deleting double elements in an array. This example removes all the duplicate elements from the array InitialArray and create from it the new FinalArray.

    Download this sample: VB .NET VB6

    Private i As Integer, InitialArray(6), FinalArray() As String

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    InitialArray(0) = "Acura"
    InitialArray(1) = "BMW"
    InitialArray(2) = "Acura"
    InitialArray(3) = "Honda"
    InitialArray(4) = "Toyota"
    InitialArray(5) = "Acura"
    InitialArray(6) = "BMW"

    Label1.Text = ""
    For i = 0 To UBound(InitialArray)
    Label1.Text = Label1.Text + Trim(CStr(i)) + " = " + InitialArray(i) + vbLf
    Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    FinalArray = DeleteDoubleElement(InitialArray)
    Label2.Text = ""
    For i = 0 To UBound(FinalArray)
    Label2.Text = Label2.Text + Trim(CStr(i)) + " = " + FinalArray(i) + vbLf
    Next
    End Sub

    ' This function removes duplicate elements from a ReceivedArray().
    ' The function does not actually remove the elements. The resulting array
    ' will have a less than or equal number of elements than the original array.
    ' The final ReturnedArray() will be returned.
    Private Function DeleteDoubleElement(ByRef ReceivedArray()) As String()
    Dim ReturnedArray() As String
    Dim col As New Scripting.Dictionary
    For i = 0 To ReceivedArray.Length - 1
    If Not col.Exists(CStr(ReceivedArray(i))) Then col.Add(CStr(ReceivedArray(i)), 1)
    Next

    ReDim ReturnedArray(col.Count - 1)
    For i = 0 To col.Count - 1
    ReturnedArray(i) = col.Keys(i)
    Next

    col = Nothing
    Return ReturnedArray
    End Function

    .Net DataGrid XP Button column Style.

    DataGridXPButtonColumn allows you to provide the datagrid interface your users are requesting, while supporting the utterly powerful Microsoft .NET DataGrid control. The DataGridXPButtonColumn makes the MS .NET DataGrid control one of the most powerful controls that you ever had used. A Rustemsoft LLC DataGridXPButtonColumn column in a .net DataGrid control gives you ability to define custom functionality for items in the grid beyond the edit, delete, select, and hyperlink features of other column types. For example, you can use a DataGridXPButtonColumn to create a "Link to a website" button.
    The DataGridXPButtonColumn has a pushbutton-style only. The button captions can be a text read from a database.
    When you define a button column, you specify a command associated with the button. When users click the button, the button's command is passed to a container where you can handle it with your custom code.

    Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    ' Set datagrid column styles
    With TableStyle.GridColumnStyles
    ' Set datagrid ColumnStyle for Car field
    .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("Car")))
    With .Item(0)
    .MappingName = "Car"
    .HeaderText = "Car Name"
    .Width = 130
    .NullText = String.Empty
    .ReadOnly = True
    End With

    ' Set datagrid ComboBox ColumnStyle for PubID field
    .Add(New DataGridComboBoxColumn(ds.Tables.Item("Companies"), 1, 0))
    ' Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    ' Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    With .Item(1)
    .MappingName = "PubID"
    .HeaderText = "Company ID"
    .Width = 200
    .NullText = String.Empty
    End With

    ......................

    ' Set datagrid XP Style Button ColumnStyle for City field
    .Add(New DataGridXPButtonColumn(SystemColors.ControlText, SystemColors.Control))
    ' Also you may set datagrid Button ColumnStyle for City
    ' field without XP Button Style as the following:
    ' .Add(New DataGridButtonColumn())
    With .Item(3)
    .MappingName = "City"
    .HeaderText = "City"
    .Width = 60
    .NullText = String.Empty
    End With

    End With

    ......................

    ' DataGridButtonAction function runs when the datagrid ButtonColumnStyle's
    ' Button control is clicked. The function receives two arguments:
    ' ColumnMappingName and ColumnValueAtRow of String type
    Public Function DataGridButtonAction(ByVal ColumnMappingName As String, ByVal ColumnValueAtRow As String)
    ' You can identify datagrid column mapping name.
    ' It gives you ability to put several datagrid
    ' Button ColumnStyles on the same datagrid
    If ColumnMappingName = "City" Then
    Dim strValue As String
    If IsDBNull(DataGrid1.Item(DataGrid1.CurrentRowIndex, 3)) Then
    strValue = "Nothing :("
    Else
    strValue = ColumnValueAtRow + " city, " + DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) + "!"
    End If
    MessageBox.Show("You have chosen " + strValue, "DataGrid Button is clicked!")
    End If
    End Function


    Learn more about DataGridColumns assembly

    .Net DataGrid Memo column Style.

    The Rustemsoft LLC DataGridMemoColumn gives you a useful Memo Field control, which presents an edit window when user selects a cell of the DataGrid Memo Column on .NET DataGrid. This provides a pop-up memo field editor that you can call from your code at any time to let users edit the text in a memo field.
    This Memo field editor provides more flexibility by updating the memo field to be used in a .NET DataGrid column.
    The DataGrid Memo Column Memo field editor is useful for showing short document contents, like memos and emails.
    When using the DataGrid Memo Column editor you are automatically provided with all general features, which any typical, contemporary word processor has.

    Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    ' Set datagrid column styles
    With TableStyle.GridColumnStyles
    ' Set datagrid ColumnStyle for Car field
    .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("Car")))
    With .Item(0)
    .MappingName = "Car"
    .HeaderText = "Car Name"
    .Width = 130
    .NullText = String.Empty
    .ReadOnly = True
    End With

    ' Set datagrid ComboBox ColumnStyle for PubID field
    .Add(New DataGridComboBoxColumn(ds.Tables.Item("Companies"), 1, 0))
    ' Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    ' Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    With .Item(1)
    .MappingName = "PubID"
    .HeaderText = "Company ID"
    .Width = 200
    .NullText = String.Empty
    End With

    .................................................

    ' Set datagrid Memo ColumnStyle for Comments field
    .Add(New DataGridMemoColumn("Car description"))
    With .Item(4)
    .MappingName = "Comments"
    .HeaderText = "Comments"
    .Width = 60
    .NullText = String.Empty
    End With
    End With

    Learn more about DataGridColumns assembly

    .Net DataGrid DateTimePicker column Style.

    The DateTimePicker ColumnStyle is used to allow the user to select a date and time, and to display that date/time in your DataGrid.

    Download VB.NET and C# that show how you can use additional column styles in .Net datagrid.

    ' Set datagrid ComboBox ColumnStyle for PubID field
    .Add(New DataGridComboBoxColumn(ds.Tables.Item("Companies"), 1, 0))
    ' Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
    ' Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
    With .Item(1)
    .MappingName = "PubID"
    .HeaderText = "Company ID"
    .Width = 200
    .NullText = String.Empty
    End With

    .................................................

    ' Set datagrid DateTimePicker ColumnStyle for DateFirst field
    .Add(New DataGridDateTimePicker())
    With .Item(4)
    .MappingName = "DateFirst"
    .HeaderText = "Date"
    .Width = 80
    .NullText = String.Empty
    End With
    End With

    Learn more about DataGridColumns assembly

    How to Trap the Tab Key in a .NET Control?

    You are trying to create a control in .NET, and your control has to catch the Tab key. It might be a grid, where you would expect Tab to move between cells, or it might be an editor control. Now you would like to catch Tab and some other navigation keys that do not call OnKeyDown or OnKeyUp. How to intercept Tabs properly in .NET?
    You have to create a class that inherits from the System.Windows.Forms.Control and override the ProcessKeyMessage method. This method is called when a control receives a keyboard message. You suppose to trap the Tab on your Button. Just override the System.Windows.Forms.Button class and create your own MyButton class:

    Public Class MyButton
    Inherits System.Windows.Forms.Button
    Public PreProcessKey As Integer = Nothing

    Public Sub New()
    MyBase.New()
    End Sub

    Protected Overrides Function ProcessKeyMessage(ByRef m As Message) As Boolean
    PreProcessKey = m.WParam.ToInt32
    End Function
    End Class


    In your custom code you will be able to identify which key has been pressed before your button was activated:


    If MyButton.PreProcessKey = Keys.Tab Then MsgBox("Tab is pressed!")

    Learn more about DataGridColumns assembly

    How to format a datagrid column using Numeric, DateTime formats? How to mask data in the column?

    These formatted intelligent DateTimeColumn, NumericColumn, TextFractionsColumn style controls can mask the date, time, numbers, digits, decimal as well as the text fractions. It gives you ability to manage the IP Address, SS#, Phone numbers, etc., and checks the validation, and automatically set the delimiter location.

    ' Set datagrid DateTime ColumnStyle for TimeFirst field
    .Add(New DataGridDateTimeColumn(DateTimeTextBox.Stencils.HHMM24, Now, ":"))
    With .Item(6)
    .MappingName = "TimeFirst"
    .HeaderText = "Time"
    .Width = 40
    .NullText = String.Empty
    End With

    ' Set datagrid Numeric ColumnStyle for Price field
    .Add(New Rustemsoft LLC.DataGridColumns.DataGridNumericColumn(, True, , , , , 2))
    With .Item(7)
    .MappingName = "Price"
    .HeaderText = "Price"
    .Width = 60
    .NullText = String.Empty
    End With

    ' Set datagrid TextFractions ColumnStyle for Phone field
    .Add(New Rustemsoft LLC.DataGridColumns.DataGridTextFractionsColumn)
    With .Item(8)
    .MappingName = "Phone"
    .HeaderText = "Phone"
    .Width = 80
    .NullText = String.Empty
    End With

    End With
    End With
    ' Add TableStyle
    DataGrid1.TableStyles.Add(TblStyle)

    ' Define NumericColumn DataGridNumericColumn object for Price field
    Dim NumericColumn As DataGridNumericColumn = DataGrid1.TableStyles(0).GridColumnStyles(7)
    ' Specify back color for the field
    NumericColumn.txtBox.box.BackColor = System.Drawing.Color.LightPink

    ' Identify PhoneColumn object that is the DataGridTextFractionsColumn?s ?child?
    Dim PhoneColumn As DataGridTextFractionsColumn = DataGrid1.TableStyles(0).GridColumnStyles(8)
    ' Specify Delimiter Character for the field
    PhoneColumn.txtBox.box.DelimiterChar = "-"

    ' Specify first fraction properties
    ' Alphanumeric symbols only are acceptable for the fraction
    PhoneColumn.txtBox.box.FractionsCode(0, 0) = "a"
    ' You can insert 3 symbols only into the first fraction
    PhoneColumn.txtBox.box.FractionsCode(0, 1) = 3

    ' Specify second fraction properties
    ' Numeric symbols only are acceptable for the fraction
    PhoneColumn.txtBox.box.FractionsCode(1, 0) = "n"
    ' You can insert 3 symbols only into the second fraction
    PhoneColumn.txtBox.box.FractionsCode(1, 1) = 3

    ' Specify third fraction properties
    ' Numeric symbols only are acceptable for the fraction
    PhoneColumn.txtBox.box.FractionsCode(2, 0) = "n"
    ' You can insert 4 symbols only into the third fraction
    PhoneColumn.txtBox.box.FractionsCode(2, 1) = 4

    ' To specify Password column only one text fraction must be defined:
    '' To let accept any symbols for the fraction we need leave first array element empty:
    'PhoneColumn.txtBox.box.FractionsCode(0, 0) = ""
    '' You can insert 30 symbols only into the password fraction
    'PhoneColumn.txtBox.box.FractionsCode(0, 1) = 30
    '' Specify Password Character for the field
    'PhoneColumn.txtBox.box.PasswordChar = "*"

    Learn more about DataGridColumns assembly

    How to draw a line in .NET? Line Control for .NET

    When a beginner who has VB6 experience first time opens .NET and just going about making a form up he/she could notice there is no Line in the .NET toolbox. What happened, where did it go?
    There is a difference from VB6 forms that Windows Forms .NET does not support the Line control.

    The Line class is based on System.Drawing namespace that provides access to GDI+ basic graphics functionality. A Line control is a graphical control that displays a horizontal, vertical, or diagonal one-pixel-wide line that can't be changed directly. The Line control can be changed dynamically at run time.
    The control class Line that is implemented in both languages (VB.Net and C#) is derived from System.Windows.Forms.Control. It overrides the OnPaint method to draw itself. The class will draw the line depending on its properties.

    Line controls can be displayed on forms, in picture boxes, and in another visual controls. You can move or resize your Line object by altering its X_Left, X_Right, Y_Left, and Y_Right properties. Also you can setup its Color property.

    Dim ln As New Line
    ln.X_Left = 20
    ln.Y_Left = 150
    ln.X_Right = 100
    ln.Y_Right = 10
    ln.Color = Color.Blue

    Download the Line Control samples for VB.NET and C#

    Protect Your .NET application - Skater .NET Obfuscator 4.80


    Visual Basic News and Information Source - www.VBWire.com




    Copyright © 2001-2014 Rustemsoft LLC All Rights Reserved