Hallo Leute
und zwar habe ich eine BindingSource die meine Datensätze aus der DB ausliest und beim initialisieren meiner form die Results in mein DGV klatscht.
Klappt auch super, sowohl refreshen, als auch Änderungen speichern.
Jetzt möchte ich über diverse Textboxen unterhalb des DGV die "Visible Rows" filtern.
da meine "uid" column mit aus der DB geladen wird (PrimeryKey, da sonst speichern nicht möglich wäre) würde ich gerne die komplette uid column ausblenden.
die anderen Columns sollen bei Textchange in den Textboxen Live gefiltert werden.
Als ich es ohne Binding Source gemacht habe ging das wie folgt:
Jetzt verwende ich diesen Code:
Wie filtere ich nun meine "visible rows" im DGV live?
PS: Falls es hilft, hier sind die column Names in meiner DB: "[uid], [Date], [Name], [PartName], [FOA], [DocName], [RevNo], [proHours]", nach Datum, Partname, FOA, Docname soll später live gefiltert werden.
und zwar habe ich eine BindingSource die meine Datensätze aus der DB ausliest und beim initialisieren meiner form die Results in mein DGV klatscht.
Klappt auch super, sowohl refreshen, als auch Änderungen speichern.
Jetzt möchte ich über diverse Textboxen unterhalb des DGV die "Visible Rows" filtern.
da meine "uid" column mit aus der DB geladen wird (PrimeryKey, da sonst speichern nicht möglich wäre) würde ich gerne die komplette uid column ausblenden.
die anderen Columns sollen bei Textchange in den Textboxen Live gefiltert werden.
Als ich es ohne Binding Source gemacht habe ging das wie folgt:
VB.NET-Quellcode
- Private Sub Databaseview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- objconnection.ConnectionString = "provider=SQLOLEDB;data source=LU0504\SQLEXPRESS;database=TimeTracker;trusted_connection=yes;"
- ' **** DataSet- und DataTable-Instanz bilden
- ds_Data = New DataSet() ' DataSet-Instanz bilden
- dt_Data = New DataTable("DBData") ' DataTable-Instanz bilden
- ds_Data.Tables.Add(dt_Data) ' DataTable dem DataSet hinzufügen
- ' **** DataAdapter-Instanz bilden, Verbindung zur DB benennen,
- ' **** SELECT-Befehl übergeben, Datensätze einlesen mittels .Fill
- da = New OleDbDataAdapter("", objconnection)
- da.SelectCommand.CommandText = "SELECT [Date], [Name], [PartName], [FOA], [DocName], [RevNo], [proHours] FROM [dataDB] where [Name] like '" & Environment.UserName & "'"
- da.SelectCommand.CommandType = CommandType.Text
- da.Fill(dt_Data) ' DataTable füllen
- ' **** Filter setzen, aber noch ohne Filterkriterien, d.h. alles wird angezeigt
- dv = New DataView(ds_Data.Tables("DBData")) ' Welche DataTable soll gefiltert werden
- 'dv.RowFilter = "name like '" & Environment.UserName & "'"
- dv.RowFilter = ""
- DBDataGrid.DataSource = dv ' Filterergebnis als Datenquelle festlegen
- txtFilterMonth.Text = MMM
- 'Data Entry Sum befüllen
- txtEntrys.Text = DBDataGrid.Rows.Count
- End Sub
- Private Sub txtFilterMonth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFilterMonth.TextChanged, txtFilterNOP.TextChanged, txtFilterFOA.TextChanged, txtFilterPNum.TextChanged
- dv.RowFilter = "Date LIKE '" & txtFilterMonth.Text _
- & "*' AND PartName LIKE '" & txtFilterNOP.Text _
- & "*' AND FOA LIKE '" & txtFilterFOA.Text _
- & "*' AND DocName LIKE '" & txtFilterPNum.Text _
- & "*' AND Name LIKE '" & Environment.UserName & "'"
- End Sub
Jetzt verwende ich diesen Code:
VB.NET-Quellcode
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
- Handles Me.Load
- ' Bind the DataGridView to the BindingSource
- ' and load the data from the database.
- Me.DBDataGrid.DataSource = Me.bindingSource1
- GetData("SELECT * FROM [dataDB] where [Name] like '" & Environment.UserName & "'")
- End Sub
- Private Sub GetData(ByVal selectCommand As String)
- Try
- ' Specify a connection string. Replace the given value with a
- ' valid connection string for a Northwind SQL Server sample
- ' database accessible to your system.
- Dim connectionString As String = _
- "data source=LU0504\SQLEXPRESS;database=TimeTracker;trusted_connection=yes;"
- ' Create a new data adapter based on the specified query.
- Me.dataAdapter = New SqlDataAdapter(selectCommand, connectionString)
- ' Create a command builder to generate SQL update, insert, and
- ' delete commands based on selectCommand. These are used to
- ' update the database.
- Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)
- ' Populate a new data table and bind it to the BindingSource.
- Dim table As New DataTable()
- table.Locale = System.Globalization.CultureInfo.InvariantCulture
- Me.dataAdapter.Fill(table)
- Me.bindingSource1.DataSource = table
- ' Resize the DataGridView columns to fit the newly loaded content.
- Me.DBDataGrid.AutoResizeColumns( _
- DataGridViewAutoSizeColumnsMode.AllCells)
- Catch ex As SqlException
- MessageBox.Show("No Connection to SQL DB!")
- End Try
- End Sub
Wie filtere ich nun meine "visible rows" im DGV live?
PS: Falls es hilft, hier sind die column Names in meiner DB: "[uid], [Date], [Name], [PartName], [FOA], [DocName], [RevNo], [proHours]", nach Datum, Partname, FOA, Docname soll später live gefiltert werden.
Danke!
Grüße,
Kevin
Grüße,
Kevin