chrisryhal
asked on
Search datagrid question
I want to place a textbox on my Windows Application form. Then, I want the user to be able to put a value in the textbox and hit a button to then search my datagrid, based on a row specific specified in a combo. It would be nice to have the row highlight.
Example:
If my datagrid is showing columns:
ID Number Description Serial
1 983 test1 093930
2 872 test2 930200
3 902 test3 930233
The user chooses "Number" from the Combobox, and types in "872" in the textbox, then row "2" highlights
Is this difficult?
Example:
If my datagrid is showing columns:
ID Number Description Serial
1 983 test1 093930
2 872 test2 930200
3 902 test3 930233
The user chooses "Number" from the Combobox, and types in "872" in the textbox, then row "2" highlights
Is this difficult?
to highlight a row in datagrid, check out the following link: http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q856q Question 5.41
You can bind the textbox to the same dataset the datagrid uses with conditions: when user chooses "Number", bind the textbox to "Number" column in the dataset, and so on.
You can bind the textbox to the same dataset the datagrid uses with conditions: when user chooses "Number", bind the textbox to "Number" column in the dataset, and so on.
Try something like this, First is the changed event for the combobox (cboWhere) , then the focus is moved to the textbox (txtsearch), then the focus moves to a search button which runs the main code (not great but it works), it highlights the search row in yellow.
You need to get the number of rows in your dataset ie.
numrows = dataset.tables(0).rows.cou
Private Sub cboWhere_SelectedIndexChan
fieldsearch = cboWhere.SelectedItem.ToSt
txtsearch.Focus()
End Sub
Private Sub txtsearch_TextChanged(ByVa
wts = txtsearch.Text
btnsearch.focus
End Sub
Try
If wts = "" Then
MsgBox("You Havent Entered Any Search Criteria", MsgBoxStyle.Critical, "Warning!")
Exit Sub
End If
If LCase(fieldsearch) = "number" Then
x = 0
For x = 1 To datarowcount
If (DataGrid1.Item(x, 1).ToString = wts Then
DataGrid1.Select(x)
DataGrid1.SelectionBackCol
DataGrid1.SelectionForeCol
End If
Next
End If
If LCase(fieldsearch) = "description" Then
x = 0
For x = 1 To datarowcount
If (DataGrid1.Item(x, 2).ToString = wts Then
DataGrid1.Select(x)
DataGrid1.SelectionBackCol
DataGrid1.SelectionForeCol
End If
Next
End If
If LCase(fieldsearch) = "serial" Then
x = 0
For x = 1 To datarowcount
If (DataGrid1.Item(x, 3).ToString = wts Then
DataGrid1.Select(x)
DataGrid1.SelectionBackCol
DataGrid1.SelectionForeCol
End If
Next
End If
Its a bit meesy but it does work for me, let me know if you want any more help
shittash, where does this variable come from
> datarowcount
> datarowcount
The dataset that your datagrid is binding to, count the number of rows in the dataset
Sorry i see what your saying, where i have put "numrows" at the top that should be datarowcount
oops.. wrong link at the wrong place...
ASKER
A lot of your examples are for ASP.NET. I am using a Windows Application, I appolagize, I probably should have stated that. I keep forgetting that ASP.NET questions are posted in the VB.NET section. I realize that ASP.NET is VB for the web, but I am not very keen on ASP.NET.
Shittash,s example is not for ASP.NET!!!
ASKER
Gotcha,
Shittash, I am having a difficult understanding how to declare portions of your code. i have included a copy of my current code.
==================CODE==== ========
Option Strict On
Imports System.Data.SqlClient
Public Class frmMainForm
Inherits System.Windows.Forms.Form
Protected ToolingData As New DataSet()
Protected Const SQL_CONNECTION_STRING As String = _
"Server=k-tsvr3;" & _
"DataBase=Triumph;" & _
"Integrated Security=SSPI"
Protected didPreviouslyConnect As Boolean = False
Protected connectionString As String = SQL_CONNECTION_STRING
Protected Const TOOLING_TABLE_NAME As String = "TL_Tooling"
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainM enu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuI tem
Friend WithEvents ToolTrackerDataGrid As System.Windows.Forms.DataG rid
Friend WithEvents txtID As System.Windows.Forms.TextB ox
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuI tem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuI tem
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents cmbStatus As System.Windows.Forms.Combo Box
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents cmbSortBy As System.Windows.Forms.Combo Box
Friend WithEvents lblStartAt As System.Windows.Forms.Label
Friend WithEvents txtStartAt As System.Windows.Forms.TextB ox
Friend WithEvents txtSearch As System.Windows.Forms.Butto n
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceM anager = New System.Resources.ResourceM anager(Get Type(frmMa inForm))
Me.ToolTrackerDataGrid = New System.Windows.Forms.DataG rid()
Me.MainMenu1 = New System.Windows.Forms.MainM enu()
Me.MenuItem1 = New System.Windows.Forms.MenuI tem()
Me.MenuItem2 = New System.Windows.Forms.MenuI tem()
Me.MenuItem3 = New System.Windows.Forms.MenuI tem()
Me.MenuItem4 = New System.Windows.Forms.MenuI tem()
Me.txtID = New System.Windows.Forms.TextB ox()
Me.Label1 = New System.Windows.Forms.Label ()
Me.cmbStatus = New System.Windows.Forms.Combo Box()
Me.Label2 = New System.Windows.Forms.Label ()
Me.cmbSortBy = New System.Windows.Forms.Combo Box()
Me.lblStartAt = New System.Windows.Forms.Label ()
Me.txtStartAt = New System.Windows.Forms.TextB ox()
Me.txtSearch = New System.Windows.Forms.Butto n()
CType(Me.ToolTrackerDataGr id, System.ComponentModel.ISup portInitia lize).Begi nInit()
Me.SuspendLayout()
'
'ToolTrackerDataGrid
'
Me.ToolTrackerDataGrid.Dat aMember = ""
Me.ToolTrackerDataGrid.Hea derForeCol or = System.Drawing.SystemColor s.ControlT ext
Me.ToolTrackerDataGrid.Loc ation = New System.Drawing.Point(8, 72)
Me.ToolTrackerDataGrid.Nam e = "ToolTrackerDataGrid"
Me.ToolTrackerDataGrid.Rea dOnly = True
Me.ToolTrackerDataGrid.Siz e = New System.Drawing.Size(728, 384)
Me.ToolTrackerDataGrid.Tab Index = 0
'
'MainMenu1
'
Me.MainMenu1.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.MenuItem1, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.MenuItem2})
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Exit"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.MenuItem4})
Me.MenuItem3.Text = "Tooling"
'
'MenuItem4
'
Me.MenuItem4.Index = 0
Me.MenuItem4.Text = "Add"
'
'txtID
'
Me.txtID.Enabled = False
Me.txtID.Font = New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.txtID.Location = New System.Drawing.Point(8, 104)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(48, 20)
Me.txtID.TabIndex = 7
Me.txtID.Text = ""
Me.txtID.Visible = False
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 9
Me.Label1.Text = "Status:"
'
'cmbStatus
'
Me.cmbStatus.Font = New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.cmbStatus.ItemHeight = 13
Me.cmbStatus.Items.AddRang e(New Object() {"ACTIVE", "INHOUSE", "OUT - VENDER PRODUCTION", "OUT- CUSTOMER", "REPAIR - VENDOR", "REPAIR - INHOUSE", "ENGINEERING", "RED TAGGED - NEW", "RED TAGGED - ENG", "RED TAGGED - APR", "INACTIVE"})
Me.cmbStatus.Location = New System.Drawing.Point(64, 40)
Me.cmbStatus.Name = "cmbStatus"
Me.cmbStatus.Size = New System.Drawing.Size(208, 21)
Me.cmbStatus.TabIndex = 8
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(8, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(48, 16)
Me.Label2.TabIndex = 10
Me.Label2.Text = "Sort By:"
'
'cmbSortBy
'
Me.cmbSortBy.Font = New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.cmbSortBy.Items.AddRang e(New Object() {"ToolID", "Tool Number", "Description", "Serial Number", "Customer", "Tool Owner", "Calibration Due", "Calibration Never Done"})
Me.cmbSortBy.Location = New System.Drawing.Point(64, 8)
Me.cmbSortBy.Name = "cmbSortBy"
Me.cmbSortBy.Size = New System.Drawing.Size(208, 21)
Me.cmbSortBy.TabIndex = 11
Me.cmbSortBy.Text = "ToolID"
'
'lblStartAt
'
Me.lblStartAt.Font = New System.Drawing.Font("Micro soft Sans Serif", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.lblStartAt.Location = New System.Drawing.Point(432, 8)
Me.lblStartAt.Name = "lblStartAt"
Me.lblStartAt.Size = New System.Drawing.Size(48, 16)
Me.lblStartAt.TabIndex = 12
Me.lblStartAt.Text = "Start At:"
'
'txtStartAt
'
Me.txtStartAt.Location = New System.Drawing.Point(488, 8)
Me.txtStartAt.Name = "txtStartAt"
Me.txtStartAt.Size = New System.Drawing.Size(160, 20)
Me.txtStartAt.TabIndex = 13
Me.txtStartAt.Text = ""
'
'txtSearch
'
Me.txtSearch.Location = New System.Drawing.Point(656, 8)
Me.txtSearch.Name = "txtSearch"
Me.txtSearch.Size = New System.Drawing.Size(56, 23)
Me.txtSearch.TabIndex = 14
Me.txtSearch.Text = "Search"
'
'frmMainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(744, 465)
Me.Controls.AddRange(New System.Windows.Forms.Contr ol() {Me.txtSearch, Me.txtStartAt, Me.lblStartAt, Me.cmbSortBy, Me.Label2, Me.Label1, Me.cmbStatus, Me.txtID, Me.ToolTrackerDataGrid})
Me.Icon = CType(resources.GetObject( "$this.Ico n"), System.Drawing.Icon)
Me.Menu = Me.MainMenu1
Me.Name = "frmMainForm"
Me.StartPosition = System.Windows.Forms.FormS tartPositi on.CenterS creen
Me.Text = "Tool Tracker .NET"
CType(Me.ToolTrackerDataGr id, System.ComponentModel.ISup portInitia lize).EndI nit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim dv As New DataView()
Private Sub frmMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frmStatusMessage As New frmStatus()
If Not didPreviouslyConnect Then
frmStatusMessage.Show("Con necting to SQL Server")
End If
Dim isConnecting As Boolean = True
While isConnecting
Try
Dim ToolTrackerConnection As New SqlConnection(connectionSt ring)
Dim ProductAdapter As New SqlDataAdapter( _
"select * from TL_Tooling", _
ToolTrackerConnection)
ToolingData.Clear()
ProductAdapter.Fill(Toolin gData, TOOLING_TABLE_NAME)
ToolTrackerDataGrid.DataSo urce = ToolingData.Tables(TOOLING _TABLE_NAM E).Default View
isConnecting = False
Catch exc As Exception
If connectionString = SQL_CONNECTION_STRING Then
frmStatusMessage.Show("Con nection Dead, Killing Tool Tracker")
End
End If
End Try
End While
frmStatusMessage.Close()
End Sub
Private Sub ToolTrackerDataGrid_Double Click(ByVa l sender As Object, ByVal e As System.EventArgs) Handles ToolTrackerDataGrid.Double Click
Dim pt As System.Drawing.Point = ToolTrackerDataGrid.PointT oClient(Cu rsor.Posit ion)
Dim hti As DataGrid.HitTestInfo = ToolTrackerDataGrid.HitTes t(pt)
If hti.Type = DataGrid.HitTestType.RowHe ader Then
txtID.Text = CType(ToolingData.Tables(0 ).DefaultV iew.Item(h ti.Row).It em("ToolID "), String)
End If
frmMainForm_ID = txtID.Text 'Module Call
Dim frmToolTrackerEditTool As New frmToolTrackerEditTool()
frmToolTrackerEditTool.Sho wDialog()
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
Dim frmToolTrackerAddNew As New frmToolTrackerAddNew()
frmToolTrackerAddNew.ShowD ialog(Me)
frmToolTrackerAddNew.Dispo se()
End Sub
Private Sub cmbStatus_SelectedIndexCha nged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbStatus.SelectedIndexCha nged
If cmbStatus.Text = "ACTIVE" Then
ToolingData.Tables(TOOLING _TABLE_NAM E).Default View.RowFi lter = ""
Else
ToolingData.Tables(TOOLING _TABLE_NAM E).Default View.RowFi lter = "StatusCode = '" & cmbStatus.Text & "'"
End If
End Sub
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
End Sub
Private Sub cmbSortBy_SelectedIndexCha nged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSortBy.SelectedIndexCha nged
Dim TS As New DataGridTableStyle()
TS.MappingName = TOOLING_TABLE_NAME
Dim Col As New DataGridTextBoxColumn()
If cmbSortBy.Text = "ToolID" Then
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolID"
Col.HeaderText = "ToolID"
Col.Width = 50
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolNumber"
Col.HeaderText = "Tool Number"
Col.Width = 200
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "Description"
Col.HeaderText = "Description"
Col.Width = 100
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "SerialNumber"
Col.HeaderText = "Serial Number"
Col.Width = 100
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "Location"
Col.HeaderText = "Location"
Col.Width = 100
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "StatusCode"
Col.HeaderText = "Current Status"
Col.Width = 150
TS.GridColumnStyles.Add(Co l)
ToolTrackerDataGrid.TableS tyles.Clea r()
ToolTrackerDataGrid.TableS tyles.Add( TS)
End If
If cmbSortBy.Text = "Tool Number" Then
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolNumber"
Col.HeaderText = "Tool Number"
Col.Width = 50
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolID"
Col.HeaderText = "ToolID"
Col.Width = 200
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "Description"
Col.HeaderText = "Description"
Col.Width = 100
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "SerialNumber"
Col.HeaderText = "Serial Number"
Col.Width = 100
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "Location"
Col.HeaderText = "Location"
Col.Width = 100
TS.GridColumnStyles.Add(Co l)
Col = New DataGridTextBoxColumn()
Col.MappingName = "StatusCode"
Col.HeaderText = "Current Status"
Col.Width = 150
TS.GridColumnStyles.Add(Co l)
ToolTrackerDataGrid.TableS tyles.Clea r()
ToolTrackerDataGrid.TableS tyles.Add( TS)
End If
End Sub
End Class
Shittash, I am having a difficult understanding how to declare portions of your code. i have included a copy of my current code.
==================CODE====
Option Strict On
Imports System.Data.SqlClient
Public Class frmMainForm
Inherits System.Windows.Forms.Form
Protected ToolingData As New DataSet()
Protected Const SQL_CONNECTION_STRING As String = _
"Server=k-tsvr3;" & _
"DataBase=Triumph;" & _
"Integrated Security=SSPI"
Protected didPreviouslyConnect As Boolean = False
Protected connectionString As String = SQL_CONNECTION_STRING
Protected Const TOOLING_TABLE_NAME As String = "TL_Tooling"
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainM
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuI
Friend WithEvents ToolTrackerDataGrid As System.Windows.Forms.DataG
Friend WithEvents txtID As System.Windows.Forms.TextB
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuI
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuI
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents cmbStatus As System.Windows.Forms.Combo
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents cmbSortBy As System.Windows.Forms.Combo
Friend WithEvents lblStartAt As System.Windows.Forms.Label
Friend WithEvents txtStartAt As System.Windows.Forms.TextB
Friend WithEvents txtSearch As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Dim resources As System.Resources.ResourceM
Me.ToolTrackerDataGrid = New System.Windows.Forms.DataG
Me.MainMenu1 = New System.Windows.Forms.MainM
Me.MenuItem1 = New System.Windows.Forms.MenuI
Me.MenuItem2 = New System.Windows.Forms.MenuI
Me.MenuItem3 = New System.Windows.Forms.MenuI
Me.MenuItem4 = New System.Windows.Forms.MenuI
Me.txtID = New System.Windows.Forms.TextB
Me.Label1 = New System.Windows.Forms.Label
Me.cmbStatus = New System.Windows.Forms.Combo
Me.Label2 = New System.Windows.Forms.Label
Me.cmbSortBy = New System.Windows.Forms.Combo
Me.lblStartAt = New System.Windows.Forms.Label
Me.txtStartAt = New System.Windows.Forms.TextB
Me.txtSearch = New System.Windows.Forms.Butto
CType(Me.ToolTrackerDataGr
Me.SuspendLayout()
'
'ToolTrackerDataGrid
'
Me.ToolTrackerDataGrid.Dat
Me.ToolTrackerDataGrid.Hea
Me.ToolTrackerDataGrid.Loc
Me.ToolTrackerDataGrid.Nam
Me.ToolTrackerDataGrid.Rea
Me.ToolTrackerDataGrid.Siz
Me.ToolTrackerDataGrid.Tab
'
'MainMenu1
'
Me.MainMenu1.MenuItems.Add
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Exit"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.MenuItems.Add
Me.MenuItem3.Text = "Tooling"
'
'MenuItem4
'
Me.MenuItem4.Index = 0
Me.MenuItem4.Text = "Add"
'
'txtID
'
Me.txtID.Enabled = False
Me.txtID.Font = New System.Drawing.Font("Micro
Me.txtID.Location = New System.Drawing.Point(8, 104)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(48, 20)
Me.txtID.TabIndex = 7
Me.txtID.Text = ""
Me.txtID.Visible = False
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Micro
Me.Label1.Location = New System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 9
Me.Label1.Text = "Status:"
'
'cmbStatus
'
Me.cmbStatus.Font = New System.Drawing.Font("Micro
Me.cmbStatus.ItemHeight = 13
Me.cmbStatus.Items.AddRang
Me.cmbStatus.Location = New System.Drawing.Point(64, 40)
Me.cmbStatus.Name = "cmbStatus"
Me.cmbStatus.Size = New System.Drawing.Size(208, 21)
Me.cmbStatus.TabIndex = 8
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Micro
Me.Label2.Location = New System.Drawing.Point(8, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(48, 16)
Me.Label2.TabIndex = 10
Me.Label2.Text = "Sort By:"
'
'cmbSortBy
'
Me.cmbSortBy.Font = New System.Drawing.Font("Micro
Me.cmbSortBy.Items.AddRang
Me.cmbSortBy.Location = New System.Drawing.Point(64, 8)
Me.cmbSortBy.Name = "cmbSortBy"
Me.cmbSortBy.Size = New System.Drawing.Size(208, 21)
Me.cmbSortBy.TabIndex = 11
Me.cmbSortBy.Text = "ToolID"
'
'lblStartAt
'
Me.lblStartAt.Font = New System.Drawing.Font("Micro
Me.lblStartAt.Location = New System.Drawing.Point(432, 8)
Me.lblStartAt.Name = "lblStartAt"
Me.lblStartAt.Size = New System.Drawing.Size(48, 16)
Me.lblStartAt.TabIndex = 12
Me.lblStartAt.Text = "Start At:"
'
'txtStartAt
'
Me.txtStartAt.Location = New System.Drawing.Point(488, 8)
Me.txtStartAt.Name = "txtStartAt"
Me.txtStartAt.Size = New System.Drawing.Size(160, 20)
Me.txtStartAt.TabIndex = 13
Me.txtStartAt.Text = ""
'
'txtSearch
'
Me.txtSearch.Location = New System.Drawing.Point(656, 8)
Me.txtSearch.Name = "txtSearch"
Me.txtSearch.Size = New System.Drawing.Size(56, 23)
Me.txtSearch.TabIndex = 14
Me.txtSearch.Text = "Search"
'
'frmMainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(744, 465)
Me.Controls.AddRange(New System.Windows.Forms.Contr
Me.Icon = CType(resources.GetObject(
Me.Menu = Me.MainMenu1
Me.Name = "frmMainForm"
Me.StartPosition = System.Windows.Forms.FormS
Me.Text = "Tool Tracker .NET"
CType(Me.ToolTrackerDataGr
Me.ResumeLayout(False)
End Sub
#End Region
Dim dv As New DataView()
Private Sub frmMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frmStatusMessage As New frmStatus()
If Not didPreviouslyConnect Then
frmStatusMessage.Show("Con
End If
Dim isConnecting As Boolean = True
While isConnecting
Try
Dim ToolTrackerConnection As New SqlConnection(connectionSt
Dim ProductAdapter As New SqlDataAdapter( _
"select * from TL_Tooling", _
ToolTrackerConnection)
ToolingData.Clear()
ProductAdapter.Fill(Toolin
ToolTrackerDataGrid.DataSo
isConnecting = False
Catch exc As Exception
If connectionString = SQL_CONNECTION_STRING Then
frmStatusMessage.Show("Con
End
End If
End Try
End While
frmStatusMessage.Close()
End Sub
Private Sub ToolTrackerDataGrid_Double
Dim pt As System.Drawing.Point = ToolTrackerDataGrid.PointT
Dim hti As DataGrid.HitTestInfo = ToolTrackerDataGrid.HitTes
If hti.Type = DataGrid.HitTestType.RowHe
txtID.Text = CType(ToolingData.Tables(0
End If
frmMainForm_ID = txtID.Text 'Module Call
Dim frmToolTrackerEditTool As New frmToolTrackerEditTool()
frmToolTrackerEditTool.Sho
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
Dim frmToolTrackerAddNew As New frmToolTrackerAddNew()
frmToolTrackerAddNew.ShowD
frmToolTrackerAddNew.Dispo
End Sub
Private Sub cmbStatus_SelectedIndexCha
If cmbStatus.Text = "ACTIVE" Then
ToolingData.Tables(TOOLING
Else
ToolingData.Tables(TOOLING
End If
End Sub
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
End Sub
Private Sub cmbSortBy_SelectedIndexCha
Dim TS As New DataGridTableStyle()
TS.MappingName = TOOLING_TABLE_NAME
Dim Col As New DataGridTextBoxColumn()
If cmbSortBy.Text = "ToolID" Then
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolID"
Col.HeaderText = "ToolID"
Col.Width = 50
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolNumber"
Col.HeaderText = "Tool Number"
Col.Width = 200
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "Description"
Col.HeaderText = "Description"
Col.Width = 100
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "SerialNumber"
Col.HeaderText = "Serial Number"
Col.Width = 100
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "Location"
Col.HeaderText = "Location"
Col.Width = 100
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "StatusCode"
Col.HeaderText = "Current Status"
Col.Width = 150
TS.GridColumnStyles.Add(Co
ToolTrackerDataGrid.TableS
ToolTrackerDataGrid.TableS
End If
If cmbSortBy.Text = "Tool Number" Then
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolNumber"
Col.HeaderText = "Tool Number"
Col.Width = 50
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "ToolID"
Col.HeaderText = "ToolID"
Col.Width = 200
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "Description"
Col.HeaderText = "Description"
Col.Width = 100
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "SerialNumber"
Col.HeaderText = "Serial Number"
Col.Width = 100
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "Location"
Col.HeaderText = "Location"
Col.Width = 100
TS.GridColumnStyles.Add(Co
Col = New DataGridTextBoxColumn()
Col.MappingName = "StatusCode"
Col.HeaderText = "Current Status"
Col.Width = 150
TS.GridColumnStyles.Add(Co
ToolTrackerDataGrid.TableS
ToolTrackerDataGrid.TableS
End If
End Sub
End Class
'Put your code in here
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
'You can use this if you assign the 'fieldsearch' variable to the selected item of the combobox
'and the "number" is your colomn name, you need one of these blocks for every colomn you want
'to search on. The wts varible is what to search for for your textbox. YOu need to put the
'corresponding field number in the item(x,?) where colomn number is ? starting at 0
If LCase(fieldsearch) = "number" Then
x = 0
For x = 1 To datarowcount
If (DataGrid1.Item(x, 0).ToString = wts Then
DataGrid1.Select(x)
DataGrid1.SelectionBackCol or = Color.Khaki
DataGrid1.SelectionForeCol or = Color.Black
End If
Next
End If
end sub
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
'You can use this if you assign the 'fieldsearch' variable to the selected item of the combobox
'and the "number" is your colomn name, you need one of these blocks for every colomn you want
'to search on. The wts varible is what to search for for your textbox. YOu need to put the
'corresponding field number in the item(x,?) where colomn number is ? starting at 0
If LCase(fieldsearch) = "number" Then
x = 0
For x = 1 To datarowcount
If (DataGrid1.Item(x, 0).ToString = wts Then
DataGrid1.Select(x)
DataGrid1.SelectionBackCol
DataGrid1.SelectionForeCol
End If
Next
End If
end sub
ASKER
Can you please explain assigning the FieldSearchVariale
Ok
your combobox has lots of items a,b,c etc
if you do something simple like
if combobox1.selecteditem = "What ever is in you list" then fieldsearch = "The Colomn name"
in the combobox changed event.
So if in your list you have all of your colomn names A, B, C etc then fieldsearch will be A or B or C etc and that will have the declare the variable and your loop for that variable will do whatever you set. So if you wanted a row to go green for one type of search and yellow for another you just change the color.green or color.black etc.
ASKER
Shittash,
My appologies, however, in this example, are you utilizing the code you posted above, because I see no reference to it. I am having horrible issues understanding what "fieldsearch" is. Also, when I place (in my case) the following in my changed event for the combo, I get declaration errors. I am extremely new to VB.NET datagrids, so I am sorry about that, and I appreciate your help.
In my case, here is what I put in my changed event:
=============
Private Sub cmbSortBy_SelectedIndexCha nged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSortBy.SelectedIndexCha nged
If cmdSortBy.selecteditem = "Tool Number" Then fieldsearch = "ToolNumber"
=============
Fieldsearch and cmbSortby are asking for declaration.
My appologies, however, in this example, are you utilizing the code you posted above, because I see no reference to it. I am having horrible issues understanding what "fieldsearch" is. Also, when I place (in my case) the following in my changed event for the combo, I get declaration errors. I am extremely new to VB.NET datagrids, so I am sorry about that, and I appreciate your help.
In my case, here is what I put in my changed event:
=============
Private Sub cmbSortBy_SelectedIndexCha
If cmdSortBy.selecteditem = "Tool Number" Then fieldsearch = "ToolNumber"
=============
Fieldsearch and cmbSortby are asking for declaration.
ASKER
I just need to understand FieldSearch and I think I should be good
ASKER
Any response?
Dim fieldsearch
Private Sub cmbSortBy_SelectedIndexCha
If cmdSortBy.selecteditem = "Tool Number" Then fieldsearch = "ToolNumber"
end sub
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
If LCase(fieldsearch) = "toolnumber" Then
x = 0
For x = 1 To datarowcount
If (DataGrid1.Item(x, 0).ToString = wts Then
DataGrid1.Select(x)
DataGrid1.SelectionBackCol
DataGrid1.SelectionForeCol
End If
Next
End If
End Sub
ASKER
.Windows.Forms.Control.x' is not accessible in this context because it is 'Private'.
ASKER
I am sorry, I simply am not familier with datagrids, but am trying the best I can. I hate to be a pain. Here is how I implemented your code. I am getting declaration errors on the "WTS" and the "DataRowCount" and that "x" can't be used because the context is Private
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
If LCase(fieldsearch) = "toolnumber" Then
x = 0
For x = 1 To datarowcount
If (ToolTrackerDataGrid.Item( x, 0).ToString = wts Then
ToolTrackerDataGrid.Select (x)
ToolTrackerDataGrid.Select ionBackCol or = Color.Khaki
ToolTrackerDataGrid.Select ionForeCol or = Color.Black
End If
Next
End If
End Sub
Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
If LCase(fieldsearch) = "toolnumber" Then
x = 0
For x = 1 To datarowcount
If (ToolTrackerDataGrid.Item(
ToolTrackerDataGrid.Select
ToolTrackerDataGrid.Select
ToolTrackerDataGrid.Select
End If
Next
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Chrisryhal,
To comment further regarding the other link. Is Toolid numeric ?
To comment further regarding the other link. Is Toolid numeric ?
ASKER
Yes
ASKER
Any luck RonaldBiemans
ASKER
Hey Shittash, thanks a lot, I was finally able to implement your code after reviewing a view MSDN documents. I appreciate all of your help
CR
CR
ASKER
As far as the solution, I marked the one that was correct. It was a "user" error on my part not being very skilled with Datagrids. I am sure others will not have issues like I did.
CR
CR
no problem buddy just ask if you want help with anything else....... points welcome of course!
http://aspnet.4guysfromrolla.com/demos/dgHighlight.aspx