Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

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.
 
Share this answer
 
Comments
paleGegg0 16-Dec-10 8:02am    
thanks. Thats helped me a lot!
Just add this code,
datagrid.AutoGenerateColumns = false;
 
Share this answer
 
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.
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>
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900