|
Visual Basic .NET Samples
|
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.
|
 .Net DataGrid Memo column Style.
The RustemSoft 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.
|
 .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.
|
 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:
|
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!")
|
 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.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.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 = "*"
|
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
|
|
|
|
|
|
environment and programming model for constructing a range of software solutions. RustemSoft develops the assemblies (dll) for .NET developers. With the RustemSoft .NET assemblies and controls, customers gained the benefits of enhanced tool and framework functionality for building enterprise-critical software.
RustemSoft?s .NET programming components are reducing the amount of code required to accomplish common tasks and delivering high-end features for advanced .NET developers.
RustemSoft presents DataGridColumns .NET assembly for VB.NET, C#, C++, J# the intelligent software package designed for .NET developers.
A quantity of jobs you may want to achieve with the Windows Forms DataGrid control are, unexpectedly, more troublesome than you might expect. Principally, this is because the Windows Forms DataGrid control is column-based, rather than cell-based. As a result, to attain most tasks, you have to work with the columns, not the cells themselves.
DataGridColumns .NET assembly from RustemSoft is a DataGrid Columns Styles software package specifically designed for .NET developers. The assembly allows you to use all strengths of the MS Windows .NET forms DataGrid control without waiving the user interface elements your customers need.
|
|
|