Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem
Hiding datagrid column problem Hiding datagrid column problem
Hiding datagrid column problem
Go Back  Xtreme Visual Basic Talk > > > Hiding datagrid column problem


Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2006, 08:44 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default Hiding datagrid column problem


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.
Reply With Quote
  #2  
Old 09-18-2006, 10:46 PM
wayneph's Avatar
waynephHiding datagrid column problem wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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...
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 09-19-2006, 08:11 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Sure:

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

Weird, huh?
Reply With Quote
  #4  
Old 09-19-2006, 08:29 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

*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.
Reply With Quote
  #5  
Old 09-19-2006, 08:30 AM
wayneph's Avatar
waynephHiding datagrid column problem wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #6  
Old 09-19-2006, 08:32 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Guess I beat you by one minute, see my post just above yours.

ps--I love your signature.

Last edited by wolfmanyoda; 09-19-2006 at 08:33 AM. Reason: added a postscript
Reply With Quote
  #7  
Old 09-19-2006, 08:36 AM
wayneph's Avatar
waynephHiding datagrid column problem wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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/.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem Hiding datagrid column problem
Hiding datagrid column problem
Hiding datagrid column problem
 
Hiding datagrid column problem
Hiding datagrid column problem
 
-->