Groups | Blog | Home
all groups > dotnet general > june 2004 >

dotnet general : Help Required with hiding DataColumns


Steve
6/28/2004 3:15:02 PM
Chris,

You can find just about everything you ever wanted to know about the WinForms DataGrid here:

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp

Check out item 5.13 for your specific issue.
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q708q

hth,
Steve


[quoted text, click to view]
Chris H.
6/28/2004 10:16:56 PM
Fellow .Netters,

I have come to an impass trying to "hide" a column on a data grid - I'm sure
it's a fairly simple thing (but so am I, that's why I'm stuck)

Imagine if you will that I have a table as structure thus (this is all an
example)

PartID (string)
Part Code (string)
Description (string)
InStock (string)

Now, the PartID field is purely an internal code which has no display value
whatsoever but is needed internally by the system for various other purpose.

My Select statement is simply "Select * from Parts...." and what I want to
do is display all the columns, except the Part ID...but retain the PartID
for other actions required later (as it's in a specific format)

Please put me out of my misery and help me solve this...

Chris....


Chris H.
6/29/2004 4:51:59 PM
Thanks....That's did the job....

[quoted text, click to view]

Sean Bright
6/29/2004 9:28:20 PM
Chris:

I know that your question has already been answered so you'll probably
never look here again, but you might try looking at the DataKeys
collection of the DataGrid to solve your problem in the future, rather
than relying on hidden columns.

Basically, when you are databinding, i.e.:

dataGrid1.DataSource = intentory.GetList();
dataGrid1.DataBind();

Add this before you DataBind() call:

dataGrid1.DataKeyField = "PartID"; // Assuming PartID is serializable

Later, in your ItemCommand event handler, you can just do this:

string partID = dataGrid1.DataKeys[e.Item.ItemIndex].ToString();

To retrieve the PartID. Makes things cleaner if you ask me... but you
didn't! :)

Enjoy,
Sean

[quoted text, click to view]
Chris H.
6/30/2004 4:52:10 PM
Thanks Sean.....any advice is good at the moment, I'm still a novice at
this...just have to work out now how to make the grid Non-Edittable with Row
Selection (just a scrolling list that the user selects and then off it goes
and does some stuff....)


[quoted text, click to view]

AddThis Social Bookmark Button