PrasangaKumarasiri
New member
- Joined
- Aug 12, 2009
- Messages
- 3
- Programming Experience
- Beginner
hi all,
i am a bigineer to this programming.
here is m question
i have a from that contains a tabcontrol,
with in that tab controls there are few tab pages and the pages contains a datagridview controls,
my problem is when i pile my data into those datagridview for first time the column indexes in the datagridview is get messed up and values that i have put into the cells in run time is not diplaying in the datagrid ,
and i am triggering the tabcontrols selected event for the populate the data into the data grid
and after I select the same tab page for second time it works fine
the problem appears only for the first time
can anyone direct me to right direction
hint: in my datagridview column indexes shows differently for the first time
and i am using datatable as a dataSource for the datagridview and also i am hidding some columns as well
my coding is below
thanks in advance
Private Sub frmIssueitem4product_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.rbtnDescription.Checked = True
sqlConnection = Getconnection()
If sqlConnection.State = ConnectionState.Closed Then
sqlConnection.Open()
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'select product and Item details in the product item table regarding to the product number
sqlCmdIssue.CommandText = "Select * from Product_Item_Info where HIN_NO ='" & frmIssue.txtHINNO.Text & "'"
sqlCmdIssue.Connection = sqlConnection
dAdpIssue.SelectCommand = sqlCmdIssue
dAdpIssue.Fill(dstIssue, "Product_Item_Info")
dstIssue.Tables("Product_Item_Info").Columns.Add("Item_Code")
dstIssue.Tables("Product_Item_Info").Columns.Add("Description")
dstIssue.Tables("Product_Item_Info").Columns.Add("Available_Quantity")
dstIssue.Tables("Product_Item_Info").Columns.Add("Location")
dstIssue.Tables("Product_Item_Info").Columns.Add("Category")
sqlCmdIssue.CommandText = "Select * from Item"
dAdpIssue.Fill(dstIssue, "Item")
sqlConnection.Close()
Dim dcKey(0) As DataColumn
dcKey(0) = dstIssue.Tables("Item").Columns("Item_NO")
dstIssue.Tables("Item").PrimaryKey = dcKey
Dim i As Integer = 0
Dim drNavigateProDItemInfo As DataRow
Dim drNavigateItem As DataRow
Dim Quantity As Double
For i = 0 To dstIssue.Tables("Product_Item_Info").Rows.Count - 1
drNavigateProDItemInfo = dstIssue.Tables("Product_Item_Info").Rows(i)
drNavigateItem = dstIssue.Tables("Item").Rows.Find(drNavigateProDItemInfo.Item(1).ToString)
'MsgBox(drNavigateProDItemInfo.Item(1).ToString)
drNavigateProDItemInfo.Item("Item_Code") = drNavigateItem.Item(1)
drNavigateProDItemInfo.Item("Description") = drNavigateItem.Item(2)
drNavigateProDItemInfo.Item("Location") = drNavigateItem.Item(5)
Quantity = drNavigateItem.Item(6).ToString
drNavigateProDItemInfo.Item("Available_Quantity") = Quantity.ToString("N", CultureInfo.InvariantCulture)
drNavigateProDItemInfo.Item("Category") = drNavigateItem.Item(8)
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' form gets the name of the current product
Me.Text = frmIssue.txtHINNO.Text & " - Issuing details"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim strColsToExport() As String = {"HIN_NO", "Item_NO", "Item_Code", "Description", "Location", "Available_Quantity", "Quantity_Required", "Category"}
dtIssueItems = dstIssue.Tables("Product_Item_Info").DefaultView.ToTable(False, strColsToExport)
dtIssueItems.Columns.Add("Issuing Amount")
dtIssueItems.Columns.Add("Remarks")
dtIssueItems.Columns.Add("Date")
dtIssueItems.Columns(0).ColumnMapping = MappingType.Hidden
dtIssueItems.Columns(1).ColumnMapping = MappingType.Hidden
dtIssueItems.Columns("Date").ColumnMapping = MappingType.Hidden
dtIssueItems.Columns("Category").ColumnMapping = MappingType.Hidden
dtIssueItems.AcceptChanges()
dgvSelectedDatagrid = Me.dgvResin
CreateDataGrid(Me.dgvResin, "Category like 'Resin'")
Me.Show()
End Sub
Private Sub tabCtrlChemicals_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles tabCtrlChemicals.Selected
Dim intTabPg As Integer = 0
intTabPg = e.TabPageIndex
Select Case intTabPg
Case 0
CreateDataGrid(Me.dgvResin, "Category like 'Resin'")
dgvSelectedDatagrid = Me.dgvResin
Case 1
CreateDataGrid(Me.gdvTypeB, "Category like 'Type B'")
dgvSelectedDatagrid = Me.gdvTypeB
Case 2
CreateDataGrid(Me.dgvTypeC, "Category like 'Type C'")
dgvSelectedDatagrid = Me.dgvTypeC
Case 3
CreateDataGrid(Me.dgvGlassFiber, "Category like 'Glass Fiber'")
dgvSelectedDatagrid = Me.dgvGlassFiber
Case 4
CreateDataGrid(Me.dgvPaint, "Category like 'Paint'")
dgvSelectedDatagrid = Me.dgvPaint
End Select
Protected Sub OntabCtrlChemicals_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabCtrlChemicals.SelectedIndexChanged
MsgBox(e.ToString())
'.OntabCtrlChemicals_SelectedIndexChanged(e)
' Select Case Me.WindowState
' Case FormWindowState.Normal
' MessageBox.Show("Form was restored", Application.ProductName)
' 'If (Me.WindowState = FormWindowState.Normal And frmAddItem.CurrentValue) Then
' ' 'frmAddItem.CurrentValue = False
' 'End If
' Case FormWindowState.Minimized
' MessageBox.Show("Form was minimized", Application.ProductName)
' Case FormWindowState.Maximized
' MessageBox.Show("Form was maximized", Application.ProductName)
' End Select
End Sub
Private Sub dgvIssueItems_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvResin.CellClick
MsgBox(e.ColumnIndex)
If e.ColumnIndex = 8 Then
Me.dgvResin.CurrentRow.ReadOnly = True
Me.dgvResin.CurrentRow.Cells(7).Value = "12356456"
MsgBox("weda weda")
End If
End Sub
Private Sub CreateDataGrid(ByVal DGV As DataGridView, ByVal strFilter As String)
DGV.DataSource = Nothing
MsgBox(DGV.Columns.Count)
If DGV.Columns.Count = 3 Then
DGV.Columns.Remove("Issue")
DGV.Columns.Remove("Re-Issue")
DGV.Columns.Remove("Date")
'dgv.
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'inserting the columns that are needed
Dim col1 As New DataGridViewButtonColumn
Dim col2 As New DataGridViewButtonColumn
col1.HeaderText = "Issue"
col1.Text = "Issue"
col2.HeaderText = "Re-Issue"
col2.Text = "Re-Issue"
col1.UseColumnTextForButtonValue = True
col2.UseColumnTextForButtonValue = True
col1.Name = "Issue"
col2.Name = "Re-Issue"
Dim datacol As New CalendarColumn
datacol.HeaderText = "Date"
datacol.Name = "Date"
DGV.Columns.Insert(0, datacol)
datacol = Nothing
dtIssueItems.DefaultView.RowFilter = strFilter
DGV.DataSource = dtIssueItems.DefaultView
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DGV.AllowUserToAddRows = False
DGV.Columns.Insert(8, col1)
DGV.Columns.Insert(9, col2)
DGV.Columns("Location").Resizable = DataGridViewTriState.True
DGV.Columns("Location").HeaderText = "LO"
DGV.Columns("Location").Width = 50
'DGV.Columns(0).DisplayIndex = 0
'DGV.Columns(1).DisplayIndex = 8
'DGV.Columns(2).DisplayIndex = 9
'DGV.Columns(3).DisplayIndex = 1
'DGV.Columns(4).DisplayIndex = 2
'DGV.Columns(5).DisplayIndex = 3
'DGV.Columns(6).DisplayIndex = 4
'DGV.Columns(7).DisplayIndex = 5
'DGV.Columns(8).DisplayIndex = 6
'DGV.Columns(9).DisplayIndex = 7
'Dim row As DataGridViewRow
'DGV.InitializeLifetimeService()
Dim intI As Integer = 0
For intI = 0 To DGV.Rows.Count - 1
DGV.Item(0, intI).Value = Date.Today.ToShortDateString
Next
DGV.CommitEdit(DataGridViewDataErrorContexts.Commit)
Me.Refresh()
End Sub
i am a bigineer to this programming.
here is m question
i have a from that contains a tabcontrol,
with in that tab controls there are few tab pages and the pages contains a datagridview controls,
my problem is when i pile my data into those datagridview for first time the column indexes in the datagridview is get messed up and values that i have put into the cells in run time is not diplaying in the datagrid ,
and i am triggering the tabcontrols selected event for the populate the data into the data grid
and after I select the same tab page for second time it works fine
the problem appears only for the first time
can anyone direct me to right direction
hint: in my datagridview column indexes shows differently for the first time
and i am using datatable as a dataSource for the datagridview and also i am hidding some columns as well
my coding is below
thanks in advance
Private Sub frmIssueitem4product_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.rbtnDescription.Checked = True
sqlConnection = Getconnection()
If sqlConnection.State = ConnectionState.Closed Then
sqlConnection.Open()
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'select product and Item details in the product item table regarding to the product number
sqlCmdIssue.CommandText = "Select * from Product_Item_Info where HIN_NO ='" & frmIssue.txtHINNO.Text & "'"
sqlCmdIssue.Connection = sqlConnection
dAdpIssue.SelectCommand = sqlCmdIssue
dAdpIssue.Fill(dstIssue, "Product_Item_Info")
dstIssue.Tables("Product_Item_Info").Columns.Add("Item_Code")
dstIssue.Tables("Product_Item_Info").Columns.Add("Description")
dstIssue.Tables("Product_Item_Info").Columns.Add("Available_Quantity")
dstIssue.Tables("Product_Item_Info").Columns.Add("Location")
dstIssue.Tables("Product_Item_Info").Columns.Add("Category")
sqlCmdIssue.CommandText = "Select * from Item"
dAdpIssue.Fill(dstIssue, "Item")
sqlConnection.Close()
Dim dcKey(0) As DataColumn
dcKey(0) = dstIssue.Tables("Item").Columns("Item_NO")
dstIssue.Tables("Item").PrimaryKey = dcKey
Dim i As Integer = 0
Dim drNavigateProDItemInfo As DataRow
Dim drNavigateItem As DataRow
Dim Quantity As Double
For i = 0 To dstIssue.Tables("Product_Item_Info").Rows.Count - 1
drNavigateProDItemInfo = dstIssue.Tables("Product_Item_Info").Rows(i)
drNavigateItem = dstIssue.Tables("Item").Rows.Find(drNavigateProDItemInfo.Item(1).ToString)
'MsgBox(drNavigateProDItemInfo.Item(1).ToString)
drNavigateProDItemInfo.Item("Item_Code") = drNavigateItem.Item(1)
drNavigateProDItemInfo.Item("Description") = drNavigateItem.Item(2)
drNavigateProDItemInfo.Item("Location") = drNavigateItem.Item(5)
Quantity = drNavigateItem.Item(6).ToString
drNavigateProDItemInfo.Item("Available_Quantity") = Quantity.ToString("N", CultureInfo.InvariantCulture)
drNavigateProDItemInfo.Item("Category") = drNavigateItem.Item(8)
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' form gets the name of the current product
Me.Text = frmIssue.txtHINNO.Text & " - Issuing details"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim strColsToExport() As String = {"HIN_NO", "Item_NO", "Item_Code", "Description", "Location", "Available_Quantity", "Quantity_Required", "Category"}
dtIssueItems = dstIssue.Tables("Product_Item_Info").DefaultView.ToTable(False, strColsToExport)
dtIssueItems.Columns.Add("Issuing Amount")
dtIssueItems.Columns.Add("Remarks")
dtIssueItems.Columns.Add("Date")
dtIssueItems.Columns(0).ColumnMapping = MappingType.Hidden
dtIssueItems.Columns(1).ColumnMapping = MappingType.Hidden
dtIssueItems.Columns("Date").ColumnMapping = MappingType.Hidden
dtIssueItems.Columns("Category").ColumnMapping = MappingType.Hidden
dtIssueItems.AcceptChanges()
dgvSelectedDatagrid = Me.dgvResin
CreateDataGrid(Me.dgvResin, "Category like 'Resin'")
Me.Show()
End Sub
Private Sub tabCtrlChemicals_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles tabCtrlChemicals.Selected
Dim intTabPg As Integer = 0
intTabPg = e.TabPageIndex
Select Case intTabPg
Case 0
CreateDataGrid(Me.dgvResin, "Category like 'Resin'")
dgvSelectedDatagrid = Me.dgvResin
Case 1
CreateDataGrid(Me.gdvTypeB, "Category like 'Type B'")
dgvSelectedDatagrid = Me.gdvTypeB
Case 2
CreateDataGrid(Me.dgvTypeC, "Category like 'Type C'")
dgvSelectedDatagrid = Me.dgvTypeC
Case 3
CreateDataGrid(Me.dgvGlassFiber, "Category like 'Glass Fiber'")
dgvSelectedDatagrid = Me.dgvGlassFiber
Case 4
CreateDataGrid(Me.dgvPaint, "Category like 'Paint'")
dgvSelectedDatagrid = Me.dgvPaint
End Select
Protected Sub OntabCtrlChemicals_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabCtrlChemicals.SelectedIndexChanged
MsgBox(e.ToString())
'.OntabCtrlChemicals_SelectedIndexChanged(e)
' Select Case Me.WindowState
' Case FormWindowState.Normal
' MessageBox.Show("Form was restored", Application.ProductName)
' 'If (Me.WindowState = FormWindowState.Normal And frmAddItem.CurrentValue) Then
' ' 'frmAddItem.CurrentValue = False
' 'End If
' Case FormWindowState.Minimized
' MessageBox.Show("Form was minimized", Application.ProductName)
' Case FormWindowState.Maximized
' MessageBox.Show("Form was maximized", Application.ProductName)
' End Select
End Sub
Private Sub dgvIssueItems_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvResin.CellClick
MsgBox(e.ColumnIndex)
If e.ColumnIndex = 8 Then
Me.dgvResin.CurrentRow.ReadOnly = True
Me.dgvResin.CurrentRow.Cells(7).Value = "12356456"
MsgBox("weda weda")
End If
End Sub
Private Sub CreateDataGrid(ByVal DGV As DataGridView, ByVal strFilter As String)
DGV.DataSource = Nothing
MsgBox(DGV.Columns.Count)
If DGV.Columns.Count = 3 Then
DGV.Columns.Remove("Issue")
DGV.Columns.Remove("Re-Issue")
DGV.Columns.Remove("Date")
'dgv.
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'inserting the columns that are needed
Dim col1 As New DataGridViewButtonColumn
Dim col2 As New DataGridViewButtonColumn
col1.HeaderText = "Issue"
col1.Text = "Issue"
col2.HeaderText = "Re-Issue"
col2.Text = "Re-Issue"
col1.UseColumnTextForButtonValue = True
col2.UseColumnTextForButtonValue = True
col1.Name = "Issue"
col2.Name = "Re-Issue"
Dim datacol As New CalendarColumn
datacol.HeaderText = "Date"
datacol.Name = "Date"
DGV.Columns.Insert(0, datacol)
datacol = Nothing
dtIssueItems.DefaultView.RowFilter = strFilter
DGV.DataSource = dtIssueItems.DefaultView
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DGV.AllowUserToAddRows = False
DGV.Columns.Insert(8, col1)
DGV.Columns.Insert(9, col2)
DGV.Columns("Location").Resizable = DataGridViewTriState.True
DGV.Columns("Location").HeaderText = "LO"
DGV.Columns("Location").Width = 50
'DGV.Columns(0).DisplayIndex = 0
'DGV.Columns(1).DisplayIndex = 8
'DGV.Columns(2).DisplayIndex = 9
'DGV.Columns(3).DisplayIndex = 1
'DGV.Columns(4).DisplayIndex = 2
'DGV.Columns(5).DisplayIndex = 3
'DGV.Columns(6).DisplayIndex = 4
'DGV.Columns(7).DisplayIndex = 5
'DGV.Columns(8).DisplayIndex = 6
'DGV.Columns(9).DisplayIndex = 7
'Dim row As DataGridViewRow
'DGV.InitializeLifetimeService()
Dim intI As Integer = 0
For intI = 0 To DGV.Rows.Count - 1
DGV.Item(0, intI).Value = Date.Today.ToShortDateString
Next
DGV.CommitEdit(DataGridViewDataErrorContexts.Commit)
Me.Refresh()
End Sub