Link to home
Create AccountLog in
Avatar of jtran007
jtran007

asked on

c# Adjust column of datagridview

Hi,

I have 5 columns, in one coumn sometimes the message short, and long. Those are long , really long. it makes the coumns looked not nice, and affect to the next column which sometimes are
pushed to the right border.
I'd like ,say ,check one of the message in any row, and if its lenght is > 40 characters, this message will be choped, and added to the end "..." indicating users can click on this row to see the full message in the drop down list. Could you please give me a smaple for this tehcnique?

Thanks,
JT
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

If you specify a width for the column when creating/designing the gridview then the columns should keep that width - in other words this should not be necessary.
Have a look at how you are setting up the gridview.
Avatar of jtran007
jtran007

ASKER

Hi,

I have...

 DataGridViewColumn par = datagrid.Columns["Products"];
 par.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;

Now I'd like to be able to click on this row, and the contend of this cell will be expanded. How can I do it?

Thanks,
JT
That is rather a different question, one I don't know the answer to offhand.
content will expand their or releated data will open on other page...?
Is this a web page or window............
If web then u can use RowDataBound Event of grid.... it is easy to play with data in this event..
As far as I understand the question my comment  #35273401 will solve the original request.
Are you saying you had fixed the width at design time but it didn't maintain it?
Hi,

For datagridview, I found the CoolTipText... attribute of the datagridview, that I can use to dynamically
change the width of the grid.

Thanks for your answer. Can I close this issue?

Regards,
JT
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Hi,

Yes you are right.: sorry.Since in my question I said if the content of a row is too long, user can click on it and display in full content. The only solution is using toottipText that my supervisor recommends.

Thanks anyway.

So can I close this issue?

Regards,
JT
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks.,
JT