It is easy to find out that a leftmost column is selected:
grid.ActiveCell.Field.ActualPosition.Column == 0
Is there an easy way to do the same about the rightmost column?
Just to clarify my understanding of the answer. It basically means that:
The field layout either does not keep track of the number of visible columns or does not expose it to the public. The only way to find it is to enumerate visible fields like this:
static int VisibleColumnCount(FieldLayout fl){ int cnt = -1; foreach (Field fld in fl.Fields) { if (fld.VisibilityResolved == Visibility.Visible && cnt < fld.ActualPosition.Column) cnt = fld.ActualPosition.Column; } return cnt + 1; }
This will not be necessarily true. If you have fields in multiple rows, you can have two fields in the Column-0 - so make sure you take this into consideration as well. You can try checking in the Fields collection of the FieldLayout and see the count of all the fields and check which Column should be the last one. Again, you can have multiple rows of fields and not have as many columns as fields.