I have a datagridview in tabpage2 and I have a search button tabpage1 to fill datagridview. When I search and click tabpage2 datagridview showing empty rows I go back to tabpage1 and click again search and then go to tabpage2 datagridview showing data, why this is happening?
Dim daPA As New OracleDataAdapter
Dim dtPA As New DataTable()
Dim cmd As New OracleCommand("select * from POLICY_SUBAGENT_DETAIL where POLICY_REFER =:Vno", sgcnn)
cmd.Parameters.Add("@Vno", OracleDbType.NVarchar2).Value = TxtPolicyRefer.Text.ToString.Trim
dtPA.Clear()
daPA = New OracleDataAdapter(cmd)
daPA.Fill(dtPA)
DgvSubAgent.AutoGenerateColumns = False
DgvSubAgent.DataSource = dtPA
If dtPA.Rows.Count > 0 Then
For i As Integer = 0 To dtPA.Rows.Count - 1
DgvSubAgent.Rows(i).Cells(0).Value = dtPA.Rows(i).Item("SUBAGENT_NAME").ToString.Trim
'DgvSubAgent.Rows(i).Cells(1).Value = dtPA.Rows(i).Item("BUSINESS_SHARE").ToString.Trim
'DgvSubAgent.Rows(i).Cells(2).Value = dtPA.Rows(i).Item("COMM_P").ToString.Trim
DgvSubAgent.Rows(i).Cells(1).Value = dtPA.Rows(i).Item("COMM_VALUE").ToString
Next
End If
I use a trick, before fill the datagridview add a line TabControl1.SelectedIndex = 1
like :
TabControl1.SelectedIndex = 1 ' where datagridview control placed,
DgvSubAgent.DataSource = dtPA
then before end sub
, add a line TabControl1.SelectedIndex = 0
--- where search button