List of unique values ​​in a column in XtraGrid

enter image description here

Is there a way to get a list of unique values ​​in any column in XtraGrid. When I click on the column heading for filtering, it shows a list (see the attached image '}').

Is there any XtraGrid object or Column object with which I can get this as an array or list?

+4
source share
1 answer

How about how you implement it as an extension method in a gridview like this

using System; using System.Linq; using System.Collections.Generic; using DevExpress.XtraGrid.Views.Grid; namespace Extensions { public static class XtraGridExtensions { public static IEnumerable<string> GetColumnsDistinctDisplayText(this GridView gv, string columnName) { if (gv == null) { throw new NullReferenceException("GridView is null"); } if (gv.RowCount == 0) { return Enumerable.Empty<string>(); } return (from int row in Enumerable.Range(0, gv.RowCount - 1) select gv.GetRowCellDisplayText(row, columnName)).Distinct().OrderBy(s => s); } } } 

and whenever you want to use it use it like

 using Extensions; ... string msg = string.Empty; foreach (var item in gridView1.GetColumnsDistinctDisplayText("columnName")) { msg += item + "\n"; } MessageBox.Show(msg); 
+3
source

Source: https://habr.com/ru/post/1385221/


All Articles