Dynamic symmetry grid - c#

I am developing a WPF application.
I have list of buttons (for example).
The list is created on run time, and on design time I don't know how many elements(buttons) are going to be in the list.
I want to order the elements in a symmetric way based on the number of buttons.
For example:
If the list contains 4 buttons, I want the grid to have 2 rows and 2
columns.
If the list contains 6 buttons, I want the grid to have 2 rows and 3
columns.
If the list contains 9 buttons, I want the grid to have 3 rows and 3
columns.
Is there a way to create this kind of grid?
What panel should I be using?

You can use WPF Grid container control. Add RowDefinitions and ColumnDefinitions to the Grid as per your requirement.
Another approach is to use a WrapPanel with a fix ItemHeight and ItemWidth.

Related

Set Row Count of Grid Control in WPF

I have a very large dataset(can be up to 3 million items) that I am retrieving on demand based on the scroll position of a grid. This means that I will never have all the items in one collection. But, I need the grid to be interactive and allow the user to scroll as if all the items were in memory.
So, I need a way to set the amount of rows (data items) so that the scroll bar will be the proper size for my database collection. I know the total number of items in the database, so I just need to set the total number of rows in the grid to match that number.
Is there a simple way to do this in WPF with a Datagrid or GridView?
Edit: The important thing is that the scroll bar is properly sized. That way the collection can be indexed based off of it.
Use event handlers for several button controls to make buttons: Next, Previous, First, Last. Parameterise the SQL called by these buttons with firstrow and lastrow inputs say 1 to 10. Each time Next is called, the SQL will spit out the next 10 rows. The rows on the grid per page will be equal to 10 in this case.

WPF Grid Control, pivot child data

Is there an effective control or method whereby I could bind a grid to a datasource, and the grid could (for lack of a better word) "pivot" a property which contains a collection to display on the same row as the parent?
Example: Datasource object has 3 properties, Name, Status, and StatusDateCollection.
StatusDateCollection could contain any number of items.
I want to bind to a grid which would display something like:
Test 1 Active 1/1/2016 2/1/2016 3/1/2016
Test 2 Inactive 7/1/2016 8/1/2016
Test 3 Suspended 3/1/2015 4/1/2015 5/1/2015 6/1/2015 7/1/2015
Do any of the popular grid controls (Telerik, Infragistics, Syncfusion, etc.) provide a way to do this?
In Xceed WPF DataGrid, Cell templates can be defined as anyway you like. I'm sure any WPF datagrid enables this in someway. So you can define a cell template for that column, where the template will display the collection data in anyway you want.

Dynamically adding columns to DataGridView as it gets expanded

I'm working on a MS Office add-in that has a DataGridView with 5 columns. Is it possible to only have as many columns shown as can fit into the sidebar, but then as the user re-sizes the add-in sidebar add more or take away columns as there becomes room for them?
u can use the Resize Event of the Datagridview and Add and Remove (or set visibilty) of all rows that are unwanted.
I guess your columns have a given size and are not sized automatically.
In that case u can:
int columnsToShow = (int)(dataGridView.Size.Width / columnWidth);
now add enough rows to match the wanted number / remove all rows that are too much
or set visibility

Add a button to the last row of the DataGrid

Using a DataGrid from WPFToolkit, I bind it to a datatable. On certain scenario I want to add a row which only contains a single button horizontally centered. The columns I defined In the DataGrid are two textcolumns and one columntemplate. Is this possible?
Grids are designed to work like tables or nets with cols and rows mostly uniform. if you need a button only at the bottom i would try to customize grid footer more than a gridrow. you could probably do everything with some templates and bit of custom code but i would really go for the footer :-)

Re-order records in gridview/bindingsource

I am using Telerik's WinForms controls and have a radGridView which is bound to a bindingsource to display my data. I would like to expand on the functionality of this a bit to give users an extra way to order the records.
I have added two command buttons to the gridview (Up, Down) to help facilitate this functionality. Basically, when the "Up" button is clicked, I would like the current row to switch places with the row above; if the "Down" button is clicked, the current row should switch places with the row below.
Example data:
1
2
3
4
5
If the "Up" button is clicked on the third row, the data should then look like so:
1
3
2
4
5
If the "Down" button is clicked on the third row, the data should look like this:
1
2
4
3
5
How can I achieve this? Do I have to modifiy the bindingsource positions of these rows, or the gridview row's index? Another way? Any examples are greatly appreciated!
Decided to use drag and drop instead of up/down buttons. All is well.

Categories