현재 vb.net windows 애플리케이션에서 작업하고 있습니다. 두 DataGridViews
있고 행을 참조하고 checkbox
datagridview2
체크 된 경우에 따라 datagridview1
밖으로 특정 행을 제거하려면 크로스 싶습니다. 이 문제는 의 프런트 엔드 사용자가 수행 한 작업의 확인란을 선택하여 업데이트 할 때 발생합니다 (datagridview2
). 그러나 모두 DataGridViews
을 새로 고침 할 때 datagridview2
은이 작업이 수행되었음을 나타내지 만 datagridview1
의 checkbox
열은 선택 취소 된 상태로 돌아가므로 프런트 엔드 사용자에게이 작업을 반복하도록 알립니다.두 개의 DataGridview를 비교하고 행 속성에 따라 행을 제거하십시오.
checkbox
열 (datagridview1
)을 제외한 모든 데이터는 SQL 테이블에 바인딩됩니다. 또한 참고, 두 테이블을 새로 고치려면로드 이벤트를 반복하는 새로 고침 단추가 있습니다.
페이지로드 이벤트 핸들러 :
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'load datagridview1'
Dim ds As New DataSet
Dim AA As New DataSet
connectionstring = "Data source = .\sqlexpress; integrated security = true"
connection = New SqlConnection(connectionstring)
sql = "SELECT Shear FROM production.dbo.stagingcompleted"
Try
connection.Open()
adapter = New SqlDataAdapter(sql, connectionstring)
adapter.Fill(ds)
connection.Close()
DataGridView1.DataSource = ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
'load datagridview2'
connectionstring = "Data source = .\sqlexpress; integrated security = true"
connection = New SqlConnection(connectionstring)
sql = "SELECT * FROM production.dbo.tblFCOrdered"
Try
connection.Open()
adapter = New SqlDataAdapter(sql, connectionstring)
adapter.Fill(AA)
connection.Close()
DataGridView2.DataSource = AA.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
DataGridView1 이벤트 처리기 (CellContentClick) :
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
'update datagridview1 to the action for that row complete'
If e.ColumnIndex <> 0 Then
Exit Sub
End If
Dim v As String = DataGridView1.Rows(e.RowIndex).Cells(1).Value
Select Case MsgBox("Are you sure shear " & v & " has been cut?", MsgBoxStyle.YesNo)
Case MsgBoxResult.No
Exit Sub
Case MsgBoxResult.Yes
Try
Dim connstring = "Data Source=.\sqlexpress; integrated security = true"
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("UPDATE Production.dbo.tblFCOrdered SET FormChannel = 1 WHERE SHEAR = '" & v & "'", conn1)
comm1.ExecuteNonQuery()
conn1.Close()
End Using
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Select
예, 그냥 downvote 전형적입니다. – Cheddar