FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister  MasterVB.NET
Visual Basic 2005 .NET Forum
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Whats the point of a GridView, I cannot hide a column????
 
Post new topic   Reply to topic    MasterVB.NET Forum Index -> Windows Forms
View previous topic :: View next topic  
Message
Author
"swatson
Newbie
Joined: 03 Jul 2006
Posts: 5

PostPosted: Mon Jul 03, 2006 1:00 pm    
Post subject: Whats the point of a GridView, I cannot hide a column????
Reply with quote

This is driving me mad, can anyone help?????? please....

I have a web app that uses several sql tables, the information I want the user to amend has two fields which are just codes and a third field which is a string, the string is what I want the users to be able to edit.

When I create a GridView and select my data source it automactically displays three fields as above, if I set the visible property to false on the two code fields the data is not loaded into the gridview???? I only set VISIBLE to false!!!!

If I create a CSS class that hides the column, true the column data vanishes but it leaves a gap in the grid!!!!

SO my point is what is the use of any of the grids if you cannot hide data from the user, I do not want them able to alter internal codes within my table!!!!!



 

Back to top
View user's profile Send private message
Author
Raj
Newbie
Joined: 04 Jul 2006
Posts: 41

PostPosted: Tue Jul 04, 2006 1:00 pm    
Post subject:
Reply with quote

You can definitely hide the columns in DataDrid.

Suppose columnID is Column1 then you can in your CB say Column1.Visible
= false; and it will hide that column.

Let me know if this not what you looking for!

Raj



 

Back to top
View user's profile Send private message
Author
Cerebrus
Intermediate
Joined: 03 Jul 2006
Posts: 342

PostPosted: Tue Jul 04, 2006 1:00 pm    
Post subject:
Reply with quote

I think swatson is talking about a DataGridView (.NET 2.0)



 

Back to top
View user's profile Send private message
Author
"swatson
Newbie
Joined: 03 Jul 2006
Posts: 5

PostPosted: Tue Jul 04, 2006 1:00 pm    
Post subject:
Reply with quote

Yes Cerebrus,

I am talking about a data bound GridView, can you help?



 

Back to top
View user's profile Send private message
Author
"swatson
Newbie
Joined: 03 Jul 2006
Posts: 5

PostPosted: Tue Jul 04, 2006 1:00 pm    
Post subject:
Reply with quote

Hi Raj, thanks for your time!

Ok, if my data grid is data bound to an sqldatasource and I use a simple select like 'SELECT * FROM customers' (lets imagine customers has two fields ccode & cname). I select the sqldatasource from within the GridView.DataSource. I run the app and yeah presto I see the
'ccode' and 'cname' fields listed in a grid, great. But I do not want to allow users to alter the customers codes for obvious reasons so I need to hide the 'ccode' column but I will need it so that I can perform the SQL update? If I set the visible property to false the
'ccode' field does not get filled by the sqldatasource anymore? so how do I know what customer the user is editing when they click the update button??????

It must be me Raj????? I must be going mad???????

Please help!!!!!



 

Back to top
View user's profile Send private message
Author
Joe Enos
Newbie
Joined: 04 Jul 2006
Posts: 7

PostPosted: Tue Jul 04, 2006 1:00 pm    
Post subject:
Reply with quote

In your element, there is a "ReadOnly" attribute, that doesn't create an editable textbox, but leaves it as plain text when you are editing the row. Is this what you're trying to do? This wouldn't actually hide it from the user, but it would not let it be edited...



 

Back to top
View user's profile Send private message
Author
Cerebrus
Intermediate
Joined: 03 Jul 2006
Posts: 342

PostPosted: Tue Jul 04, 2006 1:00 pm    
Post subject:
Reply with quote

A 1 sec google search revealed :

"How to: Hide Columns in the Windows Forms DataGridView Control"
<http://msdn2.microsoft.com/en-us/library/0c24a0d7.aspx>

HTH,

Regards,

Cerebrus.



 

Back to top
View user's profile Send private message
Author
"swatson
Newbie
Joined: 03 Jul 2006
Posts: 5

PostPosted: Wed Jul 05, 2006 1:00 pm    
Post subject:
Reply with quote

Hi Cerebrus,

I dont think you understood the question mate.

To hide a column is easy yes set the visible property of the column to false.

The thing is that stops the sql server returning the data into the cell space, this by the way is where you mis-understood me, I believe this does not happen with window forms nor does this behaviour happen with version .Net 1.0 it new to .Net 2.0

I have actually now worked out how to do this but I did not find it on the internet, and 1 sec search will not popup a simple answer because basically the docs in this area are not very good.



 

Back to top
View user's profile Send private message
Author
Cerebrus
Intermediate
Joined: 03 Jul 2006
Posts: 342

PostPosted: Wed Jul 05, 2006 1:00 pm    
Post subject:
Reply with quote

Then please tell us how you worked it out. In any case, I'm still at
.NET 1.1.

Thanks,

Cerebrus.



 

Back to top
View user's profile Send private message
Author
"swatson
Newbie
Joined: 03 Jul 2006
Posts: 5

PostPosted: Wed Jul 05, 2006 1:00 pm    
Post subject:
Reply with quote

Cerebrus no probs just your comments ticked me a bit, I do read for days before I ask a question but sometimes I am a fool and miss the obvious thats why I use you guys and hopefully in the end I can help you back! so here you go mate!!!!

All the data bound grids (GridView, DataList, DetailsView, FormView)
has been dramatically altered in the way they work between the versions 1.1 and 2.0 (I have been told, I develop in 2.0 never used 1.1). The major difference is in 1.1 if you set the visible property of a column to false the data still gets send via the server in the postback round trip and you can access it. In 2.0 this no longer is the case, if the user cannot see the column you cannot get the data!!!!

Heres how you do it, there are two methods:

1. In the RowCreated event for the grid use the following code.

if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;
e.Row.Cells[2].Visible = false; // Do not show cols 1 &
2
}

By using this code the columns are still defined within the control and the round trip happens as normal, but before the user gets chance to see the component the two columns we do not want them to access or see are removed from the display.

2.
You can use the DataKeyNames property within the component. By listing the fields you want from the data source here the 2.0 system forces data retrieval, this seems to work well but I am still experimenting.
The first method works perfectly!!!!


Hope this may help you!!!!!



 

Back to top
View user's profile Send private message
Author
Cerebrus
Intermediate
Joined: 03 Jul 2006
Posts: 342

PostPosted: Thu Jul 06, 2006 1:00 am    
Post subject:
Reply with quote

Thanks bud... and I apologize if my comment seemed presumptuous.

Regards,

Cerebrus.



 

Back to top
View user's profile Send private message
Author
Oughtsix
Newbie
Joined: 21 Jul 2006
Posts: 1

PostPosted: Fri Jul 21, 2006 1:00 pm    
Post subject:
Reply with quote

I think what you are looking for is the GridView.DataKeys property. A DataKeys property is basically a hidden column that you want to reference after a callback but you don't want the user to see. You can define multiple datakeys per row (In your case 2).

Hope this helps.



 

Back to top
View user's profile Send private message
Author
Tito
Beginner
Joined: 15 Jul 2006
Posts: 57

PostPosted: Sat Jul 22, 2006 1:00 pm    
Post subject:
Reply with quote

If you are using a DataGridView, you can simple hide the column by selecting the column and then use the visible member. So if your data is bound to DataGridView and you want to hide the 5th column,

DataGridView.Columns[4].Visible = false

If binding a data source, this must be done after the binding. This will keep the data in the DataGridView but hidden from the GUI.



 

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    MasterVB.NET Forum Index -> Windows Forms All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Archieve

Powered by phpBB © 2001, 2002 phpBB Group, used in Visual Basic 2005 .NET Forum

| Visual Basic .NET Forum | Online Recipe Archiver | Shareware Freeware PAD | Lowongan Kerja | Kamus Online | Health Supply | Digital Camera Review |
Orang Paling Keren

RSS