Click here to Skip to main content
14,240,435 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi!

Im using datagrid which is bound to my collection of objects. Problem is kind of cosmetic, but how do I remove autogenerated last column in the datagrid which is always empty.

for example my data takes 3 columns, but my app generates 3 colums + 1. Would be nicer if it was 3 columns wide.

Update: I Tried both tips, but it seems that "AutoGenerateColumns = false" messes my databinding, now it just makes rows. Any advices?

Cheers
Posted
Updated 15-Dec-10 7:28am
v3
Comments
Abdul Quader Mamun 15-Dec-10 6:44am
   
Is colun Column in title of the question?
paleGegg0 15-Dec-10 13:28pm
   
Oh, yes it is. Thank you.
Rate this:
Please Sign up or sign in to vote.

Solution 3

It looks like AutoGeneratingColumn Event[^] is being fired as each column is being autogenerated. By hooking to this event, you can cancel the creation or set the visible field of the column to false.
   
Comments
paleGegg0 16-Dec-10 8:02am
   
thanks. Thats helped me a lot!
Rate this:
Please Sign up or sign in to vote.

Solution 1

Just add this code,
datagrid.AutoGenerateColumns = false;
   
Comments
senguptaamlan 15-Dec-10 6:52am
   
@raistu please mark this as answer if it has solved your problem.
fjdiewornncalwe 15-Dec-10 14:03pm
   
How does this answer get upvoted??? It is completely wrong. The OP says directly 'that "AutoGenerateColumns = false" messes my databinding', and that is what this answer suggests. Ridiculous.
Toniyo Jackson 16-Dec-10 1:09am
   
Question has been updated later.
Rate this:
Please Sign up or sign in to vote.

Solution 2

You do not false the AutoGenerateColumns property of Datagrid, write the AutoGenerateColumn="False" in DataGrid Tag like this
<asp:DataGrid id="ItemsGrid" BorderColor="black" BorderWidth="1"  AutoGenerateColumns="false" runat="server" > /xml>
   
v2
Comments
fjdiewornncalwe 15-Dec-10 14:05pm
   
There is absolutely no difference between the two answers. This is just a different way of doing exactly the same thing. Both are valid ways to turn off column autogeneration, but both are not what the OP wants.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100