Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Hide datagrid column when using dataview

Status
Not open for further replies.

tonioJ

Programmer
Oct 7, 2002
90
PH
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...



 
Hello ThatRickGuy,

I have seen the thread. But it doesn't point out to my problem.
 
Ahh well, I thought I saw a reference to what I was thinking in there. Noticed your post after I posted here. Anyways, look into the .Select method.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
Hello ThatRickGuy,

thanks for your reply.

the .Select Method of the datagrid pertains to select a row in the grid. But it doesn't hide a column in a datagrid. Can you please give me an sample code on how you do it? Thanks in advance :)
 
Hrm, I guess I was mistaken, I thought there was a quick way to use select to only return specific rows. Are you positive that the issue you are running into is because of the data view?

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
You're right in using a Dataview, and you can use a Dataview as a datasource and have zero width columns, as I've just run an example.

Its hard to say where you're going wrong, have you definitely got some data in your table?. Also I think you have to set up the column styles, before adding the tablestyle to the grid.

This serves as a reminder for me to include the Easy Grid Builder class as an FAQ which I will try to do very soon, once I add a little code to also handle dataviews as the datasource.




Sweep
...if it works dont mess with it
 
Ok, try this. Don't hide it at the grid level. Hide it at the dataview level.
Do a .visible=False on the column.

Been there, done that.

I hope this helps.
 
Hello guys. Thank you for all your effort and reply. I got the code working. The error was pointed in this line:

ds.MappingName = dGridSummary.DataMember

I change it to:
ds.MappingName = dGridSummary.Table.TableName

 
You can also it with the dataset before binding to the datagrid :

dsKlanten.Tables("klanten").Columns("Id").ColumnMapping = MappingType.Hidden



Eric De Decker
eric.de.decker@pandora.be

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top