Hiding datagrid column problem

wolfmanyoda
09-18-2006, 07:44 PM
This has me totally stumped.
I have a dataset that fills a gridview with autogenerated columns(that may be the problem).
I set the DataSource to my dataset and then DataBind it.
The SQL query only asks for 3 fields from the table but when I run the web page it creates columns for all 12 of the fields from the table, but only has data for the 3 that I asked for.
I figured I could just hide the unwanted columns by setting their visible property to false like so:

Me.grdObjectList.Columns(1).Visible = False
Me.grdObjectList.Columns(4).Visible = False
Me.grdObjectList.Columns(5).Visible = False
etc...

But this has no effect.
Actually when I set a breakpoint to my Catch block it throws an error saying that .Columns(1) is out of range.
I don't get that because there are 12 visible columns, so how can an index of 1 be out of range?

I think it may be the autogenerated columns, this is my first ASP app so I'm a little bit out of my comfort zone.

Any suggestions would be greatly appreciated.

wayneph
09-18-2006, 09:46 PM
Yes, it has to do with the Autogenerated Columns. I'd turn those off and just select the columns you want.

However, can we see your SQL Statement? If you're truely only returning 3 columns, then all 12 shouldn't be showing up. That part is kind of confusing me...

wolfmanyoda
09-19-2006, 07:11 AM
Sure:

SELECT ObjectID, ObjectType, Title
FROM Object
WHERE ObjectID=@ObjectID
ORDER BY ObjectID

Weird, huh?

wolfmanyoda
09-19-2006, 07:29 AM
*Sigh*...

I guess I had one of those moments.
What I did was originaly created a typed dataset for another form that needed all of the columns.
So I figured I'd just add a new query to the TableAdapter asking for the 3 fields that I need on the new form since it uses the same table.
It must be showing all 12 fields since that was the original schema for the dataset. :-\

I just made a new dataset and adapter and now all is well.

But thank you for your help.

wayneph
09-19-2006, 07:30 AM
I guess the next question is how are you filling your DataSet? Did you create a DataSet that has all 12 columns up front, and are currently just using 3 of them? Or are you making any requests to grab the Schema along with the Data? Those are about the only things I can think of, that would cause the extra columns to show up.

If you were using a DataReader, or an "untyped" dataset, I don't know how you could get this.

wolfmanyoda
09-19-2006, 07:32 AM
Guess I beat you by one minute, see my post just above yours. :)

ps--I love your signature.

wayneph
09-19-2006, 07:36 AM
Well, at least it's good to know I was on the right track. :)

And you can get the shirt with that quote from ThinkGeek: http://www.thinkgeek.com/tshirts/coder/595d/.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum