Hello..
I am developing a windows app and i have a form in which i have 2 datagridviews..
dgv1 is the main gridview with checkbox column and when the user checks the box, that row should be visible in dgv3 (other datagridview)..
The code i used is :
Imports System.Data
Imports System.Data.OleDb
Imports System.EventArgs
Imports System.Data.OleDb.OleDbCommand
Imports System.Data.OleDb.OleDbConnection
Public Class BOM
Inherits System.Windows.Forms.Form
Dim wrkdir As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim bs As New BindingSource
Dim edit As Boolean
'Dim cnn As OleDbConnection
Dim cnn As New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
Private Sub ClearTextBox(ByVal root As Control)
For Each cntrl As Control In root.Controls
ClearTextBox(cntrl)
If TypeOf cntrl Is TextBox Then
CType(cntrl, TextBox).Text = String.Empty
End If
Next cntrl
End Sub
Private Sub BOM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'HemDatabase1DataSet3.partno' table. You can move, or remove it, as needed.
'Me.PartnoTableAdapter.Fill(Me.HemDatabase1DataSet3.partno)
dgv1.DataSource = Me.HemDatabase1DataSet3.partno
bs.DataSource = ds.Tables(0)
End Sub
Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
ClearTextBox(Me)
End Sub
Private Sub FillByToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillByToolStripButton.Click
ds.Tables.Clear()
If TypeToolStripTextBox.Text <> "" Then
Dim sql As String = "SELECT * from (partno) WHERE type='" & TypeToolStripTextBox.Text & "';"
Dim cmd As New OleDbCommand(sql, cnn)
da = New OleDbDataAdapter(cmd)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
dgv1.DataSource = bs
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ds.Tables.Clear()
Dim sql As String = "SELECT * From partno;"
Dim cmd As New OleDbCommand(sql, cnn)
da.SelectCommand = cmd
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.Fill(ds, "partno")
bs.DataSource = ds.Tables(0)
dgv1.DataSource = bs
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim f21 As New SelectedBom()
f21.Show()
End Sub
Private Sub dgv1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv1.CellContentClick
End Sub
Private Sub Btn_Transfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Transfer.Click
Dim IsRowSelected As Boolean
Dim SelectedValue As String
Dim i As Integer
With Me.dgv3
'.Rows.Clear()
For i = 0 To Me.dgv1.RowCount - 1
IsRowSelected = Me.dgv1.Rows(i).Cells(1).Value
If IsRowSelected = True Then
.Rows.Add(1)
SelectedValue = Me.dgv1.Rows(i).Cells(0).Value
.Rows(.RowCount - 1).Cells(0).Value = SelectedValue
End If
Next
End With
End Sub
End Class
I was getting an error on the line :
.Rows.Clear()
saying cannot clear the rows
and then, on commenting it, the error is on line :
.Rows.Add(1)
Please help me as to how should i proceed with this !!
Thank You !!