WinUI3: How to sort datagrid groups? - datagrid

I'm using the Windows Community Toolkit Datagrid.
I am binding the the datagrid's ItemSource to a grouped CollectionViewSource.
<ctWinUI:DataGrid
ItemsSource="{x:Bind MyCollectioViewSourceView, Mode=OneWay}"
By default groups are sorted alphabetically:
How can I implement custom sorting?
(Note I know how to sort datagrid rows, this is specifically for sorting datagrid groups.)
I have seen similar questions for the WPF datagrid, but the WinUI datagrid is different.

Just order the Source of the grouped MyCollectioViewSourceView, e.g.:
CollectionViewSource cvs= new CollectionViewSource();
cvs.IsSourceGrouped = true;
cvs.Source = groupedItems.OrderByDescending(x => x.Key).ToList();

Related

Can the devexpress Gridview Control be used completely in unbound mode?

I want to use the Aspx gridview with out connect it to datasource
From: Add new unbound row in bound AspxGridView
The ASPxGridView can't display unbound rows. As a possible solution,
create an intermediate in-memory datasource (e.g. DataTable), copy
rows from your read-only datasource into it, and bind it to the grid.
Then, you'll be able to programmatically add new rows to this
datasource.
You can manage in memory DataSet(other datasource types), to populate data in the grid. There are lots of DevExpress threads about such type of requirements. I suggest you to go through them and implement in the way that you like to prefer.
ASPxGridView - How to manipulate data without data source
aspxgridview without datasources
Add new unbound row in bound AspxGridView

How to programmatically update datagrid columns headerText

I have a Datagrid that is being populated by an ArrayCollection (rows) of Arrays (columns). I need to update the headerText of each column based on a List that will correspond with the total number of items within each array in the arraycollection.
What is the best way of doing this?
I know that I can set a listener in the List and update the headerText using (matrixDatagrid.columns[i] as DataGridColumn).headerText but I am looking for a cleaner solution.
Is there a way to do this using an itemRenderer in the Datagrid?
Adobe has a write up on Passing values to headerrenderer that has an example on how to dynamically pass data to your HeaderRenderer. Hopefully it helps. :)

flex datagrid: how to do a multiple selection programmatically

I have I datagrid, on which I want to select multiple rows on a other user interaction than the one intended by the Programm. I'm wondering, whether I can programmatically select some rows depending only on code?
Thanks,
Markus
You can set the selectedIndices property to an array of indexes, or the selectedItems property to an array of items.
For example:
myDataGrid.selectedIndices = [1,2,5,8];

Filter columns in flex datagrid using CheckBox

I have a flex datagrid with 4 columns.I have a comboBox with 4 checkboxes,containing the column names of datagrid as its label.I want the datagrid to display only those columns which are selected in combobox.Can anyone tell me how this filtering of columns in datagrid can be done?
Thanks in advance.
You can manipulate the columns attached to the data grid using the .columns property. Bear in mind that this method is a getter and returns you a copy of the list of columns on the datagrid, so if you manipulate its contents you have to apply those changes back to the data grid using the equivalent setter, e.g.
<mx:DataGrid id="dg" />
in ActionScript code
var columns:Array = dg.column;
columns.push(new DataGridColumn("hello"));
dg.columns = columns;
In your case you could hold your master list of columns in a separate array and push them onto the data grid as the user checks and un-checks them from the list in your comboBox.
Alternatively you can iterate through the column list looking for the ones which are checked in your comboBox and set their .visible property accordingly.
HTH

Display rows in multiple columns in Asp.net Gridview

By default each row of a Gridview maps to each row in a datatable or dataset attached to its datasource. But what if I want to display these rows in multiple columns. For example if it has 10 rows, 5 rows each should be displayed in 2 columns side by side. Also can I do this with the Infragistics grid. Is this possible?
You can use a DataList control instead. It has a RepeatColumns property that you can define the number of columns you want to display.
In .NET Framework 3.5, there is an even better solution, the ListView control. You can find further information about how to use the ListView control here.
If this is a pure coding exercise, then bind to the RowDataBound event of the Gridview. That way, you can do:
e.Row.Cells(2).Text = e.Row.Cells(1).Text
This would place the text from column 1 in column 2 after it has been pulled from the database. You can also dynamically create columns using a similar method.
Re-reading, I think I misunderstand your problem though.
Can't you just put two identical bound columns one after the other?

Resources