Domanda

I have a datagridview with the columns

col A | col B | ... | col M | col N 

Now I want to freeze col N on the right side, so that when the user scrolls the datagridview horizontally the columns A,..., M can be scrolled horizontally, but col N remains frozen.

Now I have tried setting the Frozen attribute for col N but then all the columns to the left of the frozen column are also frozen, which I do not want. The best that I have been able to come up with is to reverse the columns of the DataTable bound to the DataGridView so that it now has the order

col N | col M | ... | col B | col A

and then draw the DataGridView from RightToLeft so that the columns are reversed again and then shown as

col A | col B | ... | col M | col N 

Another solution that I tried is to extract the rightmost columns that have to be frozen and place them in a different DataGridView on the right side and the remaining columns in the original DataGridView and then synchronize the vertical scroll for both of them. Now my question is are there any better ways to do this, if not which of the above should I prefer?

or in other words :

How can I freeze columns on the right side of a datagridview without freezing the other columns ?

È stato utile?

Soluzione

joe, in c# DataGridView yo can freeze the column in the middle of the table, only on the start of it, just like in excel. It makes sense, because if we freeze the middle column then we don't know how it should react in the sides. will we need two scroll bars for the different sides?

from here you can see that it is the c# wanted behavior:

When a column is frozen, all the columns to its left (or to its right in right-to-left languages) are frozen as well. The frozen and unfrozen columns form two groups. If column repositioning is enabled by setting the AllowUserToOrderColumns property to true, the user cannot drag a column from one group to the other.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top