WAMPSERVER

WampServer is a Windows web development environment. It allows you to create web applications with Apache2, PHP and a MySQL database. Alongside, PhpMyAdmin allows you to manage easily your databases.

SelectedIndexChanged

 

Private Sub cboUOMKey_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboUOMKey.SelectedIndexChanged
uomView.RowFilter = “uomkey = ‘” & Trim(cboUOMKey.Text) & “‘”
If uomView.Count > 0 Then
txtUOMDescription.Text = uomView.Item(0).Item(“uomdescription”).ToString
Else
txtUOMDescription.Text = “”
End If
End Sub

Call UOMSelect

Script

Private Sub btnUOM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUOM.Click
frmUOMSelect.ShowDialog()
If frmUOMSelect.isOK Then
If cboUOMKey.Items.Count = 0 Then
fillUOM()
For i = 0 To uomView.Table.Rows.Count – 1
cboUOMKey.Items.Add(uomView.Item(i).Item(“uomkey”).ToString)
Next
End If
cboUOMKey.Text = frmUOMSelect.selected_uom
End If
End Sub

 

Example for select

It’s example for help search in datagridview.

Capture

Script :

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class frmUOMSelect
Dim strCon As String
Dim uomView As DataView

Public isOK As Boolean = False
Public selected_uom As String = “”
Private Sub frmUOMSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
fillUOM()
DataGridView1.DataSource = uomView
DataGridView1.RowHeadersVisible = False
DataGridView1.Columns(0).HeaderCell.Value = “UOM Key”
DataGridView1.Columns(1).HeaderCell.Value = “UOM Description”
End Sub
Private Function fillUOM() As Boolean
strCon = modDataSource.strCon_Online
Try
Dim cn As New SqlConnection(strCon)
cn.Open()

Dim strSelect As String = “select uomkey,uomdescription from uom”
Dim dscmd As New SqlDataAdapter(strSelect, cn)

Dim dtable As New DataTable()
dscmd.Fill(dtable)

uomView = New DataView(dtable)
cn.Close()
fillUOM = True
Catch ex As Exception
MsgBox(“Connection to database online failed.”)
fillUOM = False
End Try
End Function
Private Sub filterUOMView()
Dim fltstr As String = “”
If txtUOMDescription.Text <> “” Then
fltstr = “uomdescription like ‘%” & Trim(txtUOMDescription.Text) & “%'”
End If
If txtUOMKey.Text <> “” Then
If fltstr <> “” Then
fltstr = fltstr & ” and ”
End If
fltstr = fltstr & ” uomkey like ‘%” & Trim(txtUOMKey.Text) & “%'”
End If
uomView.RowFilter = fltstr
End Sub

Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
isOK = True
Dim idx As Integer = DataGridView1.CurrentRow.Index
selected_uom = uomView.Item(idx).Item(“uomkey”).ToString
Me.Close()
End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub

Private Sub txtUOMKey_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUOMKey.TextChanged
filterUOMView()
End Sub

Private Sub txtUOMDescription_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUOMDescription.TextChanged
filterUOMView()
End Sub
End Class

 

Populate combobox from database vb.net

Call to populate

fillUOM()
For i = 0 To uomView.Table.Rows.Count – 1
cboUOMKey.Items.Add(uomView.Item(i).Item(“uomkey”).ToString)
Next

Function to fill

Private Function fillUOM()
strCon = modDataSource.strCon_Online

Try
Dim cn As New SqlConnection(strCon)
cn.Open()

Dim strSelect As String = “select uomkey,uomdescription ” _
& “from uom”
Dim dscmd As New SqlDataAdapter(strSelect, cn)

Dim dtable As New DataTable()
dscmd.Fill(dtable)

uomView = New DataView(dtable)
cn.Close()
fillUOM = True
Catch ex As Exception
MsgBox(“Connection to database online failed.”)
fillUOM = False
End Try

End Function