Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim cn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim dv As New DataView
Dim rpt As rpt1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn = New SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True")
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F6 Then
rpt = New rpt1
dgv.CommitEdit(DataGridViewDataErrorContexts.Commit)
ds.AcceptChanges()
ds.Tables("Data").DefaultView.RowFilter = "Column1 = 1"
rpt.SetDataSource(ds.Tables("Data").DefaultView)
crv.ReportSource = rpt
End If
End Sub
Private Sub btn_Show_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Show.Click
da = New SqlDataAdapter("Select * from test", cn)
ds.Reset()
da.Fill(ds, "Data")
If ds.Tables("Data").Columns.Contains("Column1") Then ds.Tables("Data").Columns.Remove("Column1")
ds.Tables("Data").Columns.Add(New DataColumn("Column1", GetType(Boolean)))
dgv.DataSource = ds.Tables("Data")
End Sub
Private Sub btn_Filter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Filter.Click
rpt = New rpt1
ds.Tables("Data").DefaultView.RowFilter = "Column1 = 1"
rpt.SetDataSource(ds.Tables("Data").DefaultView)
crv.ReportSource = rpt
End Sub
Private Sub btn_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Clear.Click
ds.Tables("Data").DefaultView.RowFilter = ""
End Sub
End Class