thanks for the quick reply and example, ill try to grasp the concept of those codes...
anyway here's my code for dgv1,dgv2 and form_load...
#Region "LOAD_REQUISITION_ITEM"
'here's my code for dgv1
Public Sub LoadRequisitionItem()
Try
con = New SqlClient.SqlConnection(My.Settings.PSMSConnectionString)
con.Open()
ds = New DataSet
dt = New DataTable
ds.Tables.Add(dt)
adptr = New SqlClient.SqlDataAdapter("SELECT RIS_NO, STOCK_NO, UNIT, DESCRIPTION, QUANTITY FROM tblREQUISITION WHERE RIS_NO = '" & listviewItemMC1 & "'", con)
adptr.Fill(dt)
DataGridViewMC1_RIS.DataSource = dt.DefaultView
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
'code for dgv2(the problem is here, it seems that there's no problem on my looping structure(i guess) but on how i display the query result set... )
Public Sub LoadBalance()
Try
con = New SqlClient.SqlConnection(My.Settings.PSMSConnectionString)
con.Open()
For m As Integer = 0 To DataGridViewMC1_RIS.Rows.Count - 1
Dim value As Integer = DataGridViewMC1_RIS.Rows(0).Cells(1).Value.ToString
ds = New DataSet
dt = New DataTable
ds.Tables.Add(dt)
adptr = New SqlClient.SqlDataAdapter("SELECT BALANCE_QTY,DAYS_TO_CONSUME FROM tblSTOCK_CARD WHERE STOCK_NO = '" & DataGridViewMC1_RIS.Rows(0).Cells(1).Value.ToString & "'", con)
adptr.Fill(dt)
DataGridViewMC1_RIS_STATUS.DataSource = dt.DefaultView
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
#End Region
Private Sub frmMonitoringLoadData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If TabControlMainContent.SelectedIndex = 0 Then
LoadRISData()
LoadRequisitionItem()
LoadBalance()
Dim no As Integer
no = DataGridViewMC1_RIS.Rows.Count.ToString
DataGridViewMC1_RIS_ISSUANCE.Rows.Clear()
DataGridViewMC1_RIS_ISSUANCE.Rows.Add(no)
DataGridViewMC1_RIS_ISSUANCE.ReadOnly = False
With Me.DataGridViewMC1_RIS
.RowsDefaultCellStyle.BackColor = Color.White
.RowsDefaultCellStyle.ForeColor = Color.Black
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightSteelBlue
End With
With Me.DataGridViewMC1_RIS_ISSUANCE
.RowsDefaultCellStyle.BackColor = Color.White
.RowsDefaultCellStyle.ForeColor = Color.Black
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightSteelBlue
End With
With Me.DataGridViewMC1_RIS_STATUS
.RowsDefaultCellStyle.BackColor = Color.White
.RowsDefaultCellStyle.ForeColor = Color.Black
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightSteelBlue
End With
ElseIf TabControlMainContent.SelectedIndex = 1 Then
LoadSCData()
End If
End Sub
Private Sub DataGridViewMC1_RIS_STATUS_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DataGridViewMC1_RIS_STATUS.Scroll
If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then
Dim i As Integer = DataGridViewMC1_RIS_STATUS.FirstDisplayedScrollingRowIndex
DataGridViewMC1_RIS.FirstDisplayedScrollingRowIndex = i
DataGridViewMC1_RIS_ISSUANCE.FirstDisplayedScrollingRowIndex = i
End If
End Sub
#End Region