How to freeze columns and rows in WPF Grid - c#

I'd like to "freeze" the columns and rows in WPF.
I want to implement a table (state machine), where in the first row are states and in first column are commands. The rest of the cells are filled with events.
To improve usability, I'd like to keep the first row and first column visible all the time, so even at the very bottom of the table the states and commands are visible.
The DataGrid offers this kind of functionality but DataGrid cells don't look flexible enough. I'd like to use Grid.
The ScrollViewer is basically what I need, but i haven't figured out how to use it for multiple Grids at the same time.
Is there any way to freeze first row and first column (at the same time)?

I don't think that there is no way to freeze columns or rows of a Grid. But you can use 4 Grids. Syncronize the Column and Rowsize with SharedSizeGroup.

Related

C# Listview adds an extra column header in Details view

I have ListView, where I'm adding just 2 columns with some data. the view I have set is details view.When I run the application, I see a third column header in the end, which appears to be an extra column. So how can I avoid this third column/ column header coming in the output and just show 2 columns.
My guess is that you do not see an extra column, but that your ListView simply is wider than your two columns.
Make sure your two columns take up all the space in your listview by either making them wider or setting up the last column (your second one) to use up all available horizontal space (something like width="*" or so).

How to make last row in a dataGridView on a Windows Form to be displayed all the time while still allowing the remaining rows to scroll

I have a dataGridView which has about 30 rows in it and last row of it contains sum of all the cells in that particular column. Now I would like to freeze the last row which has sum while still allowing the remaining rows to scroll.
dataGridViewPaymentsReceived.Rows[dataGridViewPaymentsReceived.Rows.Count-1].Frozen = true;
The above code freezes the entire dataGridView and doesn't allow me to scroll on it.
Can anyone suggest me a good way to keep the last row displayed all the time even when I scroll on the dataGridView?
The easiest solution would be to create a second DataGridView directly below the first. Then manually populate it with the single row that you want to be displayed every time the first datagrid binds to data.
To make it appear totally seamless, don't forget to hide the column headers in the 2nd datagrid:
dataGridView2.ColumnHeadersVisible = false;
See this answer for more info.

Equivalent for DataGrid RowDetails template in Winforms DatagridView

I need to create an expander in my datagridview that adds additional info about that row to the datagridview when selected, and hides the same when collapsed.
This is possible by creating RowDetails templates in WPF, but can I do something similar in winforms datagridview? A workaround I'd thought of was dynamically adding objects to the datagridview on expand/collapse, but it won't work in this case because the number, type, arrangement of columns is very different for the details rows than the data rows.
Can RowTemplate possibly help? All examples I've seen thus far use rowtemplate only to fix height, width etc of rows in a datagridview and nothing else.
You can use ToolTip for selected row if you want to show additional data info.

add another column header on top to C# datagridview winform

I have a bounded datagridview with a lot of columns (around 40) and I'm wondering if I can add another column header on top of the default headers made with the SQL query. So it would look like a multi-row column header with some spanned columns.
I've seen some solutions by painting custom column headers but they involve creating all the columns. What if I leave the default headers made with the SQL query and just add a spanned column on top of it, is that possible?
DataGridView has no support for spanned columns. You will need to either look at third party, custom rendering, or a second control parked just above your grid.

Customise a bound datagridview

Howdy, using vs2008 winforms.
I want to be able to use a slightly customised datagridview but cant think of a way to do it.
i have
1. a sqldataadaptor fill a dataset
2. a binding source bound to the dataset
3 a datagridview with the bindingsource set as the datasource.
I want the binding to allow sync between the dataset and datagridview, so i can edit data and then update to database with sqldataadaptor. update.
I want to show some custom columns that are calculated results.
And i want to show a final bottom row that is totals of all the columns in the DVG.
My problem is once the DGV is bound i cant add a custom column or row, it wont let me.
I know i could add it directly to the dataset that is the underlying datasource but then by changing the structure of the dataset i cant update to a database once edits have taken place.
or can i ???
Can someone tell me how i can add my custom columns and a final total row to a bound DGV.
Also while im here, if i click on the top of a column to sort on it, in a bound DGV, will it also re-sort the underlying dataset, so i i edit things will still stay synced ?
thanks in advance for any help
Yes, you can.
The adapter does not care about structure. It only cares about column names used in the Select/Insert/Update/Delete commands. You can add custom columns, expression columns, columns for subtotals, columns for totals, or whatever you need. Even change the order of the columns. I do advise adding a sort column, so you can keep the custom rows in the proper place when you or the user sorts.
You can do the same thing for custom rows. When you update through the adapter, you handle the RowUpdating event and set the SqlRowUpdatingEventArgs.Status to SkipCurrentRow for these custom rows. I strongly advise creating a row type column so you know which rows to skip when updating. (You can also use the sort column's value as a key to skip rows.)
There are a couple of articles on MSDN or KB that illustrate how to add total rows.
"How to sum the fields in a Windows Forms DataGrid control and then display the calculated totals in a footer by using Visual Basic .NET" at http://support.microsoft.com/kb/836672.
In my experience, manipulate the data table first before binding. Do what you need to do in order to support the grid and the grid's interface. It is okay to manipulate the data, add/change/remove columns and rows, then rebind when needed.
To be able to add additional unbound columns to your DataGridView you could also set its AutoGenerateColumns property to false and then add custom columns with the following method:
dataGridView->Columns->Add(...)
To calculate the contents of the unbound columns you can handle the CellValueNeeded and CellValuePushed events but you must set the DataGridView into 'virtual mode' by setting the VirtualMode property to true in order for the eventhandlers to be invoked.
Hope this helps a little....

Categories

Resources