I have a datagrid that uses dataview for displaying the records. I want to hide some columns in the datagrid but
It returns an error but when using a dataset it has no problem. The reason why I use dataview is because I am filtering some information base on the criteria set by the user. Is there another way to work out with this? Please help because I am stuck in this situation for two days.
This is the error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The code that I have is below:
Dim strEmpList As String
Dim iCtr As Integer
dim ds as New DataGridTableStyle
strSQL = "sp__k_payroll_compute_grosspay '" & Trim(CoCode) & "','" & _
Trim(cmboPeriod.Text) & "','" & _
Trim(strEmpList) & "'"
daCompute = New SqlClient.SqlDataAdapter(strSQL, dbCnn)
dsCompute.Clear()
daCompute.Fill(dsCompute, "sp__k_payroll_compute_payroll")
dvCompute = New DataView(dsCompute.Tables("sp__k_payroll_compute_payroll"), "", "Emp_code", DataViewRowState.CurrentRows)
'--set the datasource of datagrid to dvcompute
dGridSummary.DataSource = dvCompute.Table.DefaultView
'--format the display datagrid ---
ds.MappingName = Nothing
ds.MappingName = dGridSummary.DataMember
dGridSummary.TableStyles.Clear()
dGridSummary.TableStyles.Add(ds)
dGridSummary.TableStyles(0).GridColumnStyles(0).Width = 0 <----- error occurs in this line
dGridSummary.TableStyles(0).GridColumnStyles(1).Width = 150
dGridSummary.TableStyles(0).GridColumnStyles(2).Width = 380
dGridSummary.TableStyles(0).GridColumnStyles(3).Width = 0
dGridSummary.TableStyles(0).GridColumnStyles(4).Width = 0
dGridSummary.TableStyles(0).GridColumnStyles(5).Width = 0
dGridSummary.TableStyles(0).GridColumnStyles(1).HeaderText = "ACCT CODE"
dGridSummary.TableStyles(0).GridColumnStyles(2).HeaderText = "DESCRIPTION"
Thank you for your reply in advance...
It returns an error but when using a dataset it has no problem. The reason why I use dataview is because I am filtering some information base on the criteria set by the user. Is there another way to work out with this? Please help because I am stuck in this situation for two days.
This is the error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The code that I have is below:
Dim strEmpList As String
Dim iCtr As Integer
dim ds as New DataGridTableStyle
strSQL = "sp__k_payroll_compute_grosspay '" & Trim(CoCode) & "','" & _
Trim(cmboPeriod.Text) & "','" & _
Trim(strEmpList) & "'"
daCompute = New SqlClient.SqlDataAdapter(strSQL, dbCnn)
dsCompute.Clear()
daCompute.Fill(dsCompute, "sp__k_payroll_compute_payroll")
dvCompute = New DataView(dsCompute.Tables("sp__k_payroll_compute_payroll"), "", "Emp_code", DataViewRowState.CurrentRows)
'--set the datasource of datagrid to dvcompute
dGridSummary.DataSource = dvCompute.Table.DefaultView
'--format the display datagrid ---
ds.MappingName = Nothing
ds.MappingName = dGridSummary.DataMember
dGridSummary.TableStyles.Clear()
dGridSummary.TableStyles.Add(ds)
dGridSummary.TableStyles(0).GridColumnStyles(0).Width = 0 <----- error occurs in this line
dGridSummary.TableStyles(0).GridColumnStyles(1).Width = 150
dGridSummary.TableStyles(0).GridColumnStyles(2).Width = 380
dGridSummary.TableStyles(0).GridColumnStyles(3).Width = 0
dGridSummary.TableStyles(0).GridColumnStyles(4).Width = 0
dGridSummary.TableStyles(0).GridColumnStyles(5).Width = 0
dGridSummary.TableStyles(0).GridColumnStyles(1).HeaderText = "ACCT CODE"
dGridSummary.TableStyles(0).GridColumnStyles(2).HeaderText = "DESCRIPTION"
Thank you for your reply in advance...