DataGridView minimal amount of rows - c#

I'm pretty much to C# and I'm trying to create a simple network analyzer. I want to be able to see packets in a datagridview. The imagined lay-out can be compared with tools like wireshark. I would like my datagridview to always be "filled". By filled I mean that it always contains rows even if these are empty.
When starting the application for example I would like the grid to be fully filled with rows. The total height of the gridView is a multiple of the row height, so it contains enough rows so it's exactly 100% filled. When adding data however I would like that these empty rows do not count so data overwrites these empty rows, and when removed these rows return if otherwise the DataGridView would not be fully filled. I realize I might explain this a bit poorly but I'm not sure how I could try to bring across what I mean otherwise. The way Excel works would be ideal for example. You start with a full screen with empty cells, and you can add things to them. If you add more data than fits a scoll bar gets introduced to still be able to see all data. When you remove it the scrollbar becomes smaller until eventually it's not needed anymore but the cells remain shown. (even if empty)
Thanks in advance,
Arnold
-edit-
Regarding height of things: I'd probably want things to be resizable in the future. So that information could probably not be exploited.

Wrap a DataGridView with a user control to override adding and removing rows.
If you are removing a row - it must be real (not marked as "place holder" [tag?]).
and if your Count is less than IdealCount, add a "place holder" row.
If you are adding a row - if your Count is less than IdealCount, remove the last "place holder" row.
Initialize with IdealCount number of "place holder" rows.
Let the rows be sorted by a hidden column of default value 0 and a value of 1 for "place holders" or simply maintain the rows order yourself in the Add override. This way the "place holders" will always be last (and there won't be any, if Count > IdealCount).

Related

UWP - Matrix With Grid

I first would like to say that I am fairly new to UWP, and my experience with Android is probably leading some some assumptions on my end. There may be a better way about this, but so far I have been trying to use the Grid class, but it doesn't seem to work in a way that I would expect.
Basic Idea
I am trying to create a UWP application with the ability of organizing elements in a matrix, where each row and column represents some category, and whatever element that is within both row and column categories is placed in that cell. One or more elements can be listed in each matrix coordinate. An image for reference is below:
To give a more clearer/specific example, let's say the Elements were Employees, rows were Teams, and columns were disciplines (Testing, Dev, Management)
Comparing different category-types can be useful for displaying information, but this will have greater importance beyond just names, so this is only a simplified example. Also, as shown in the example, the number of rows and columns is determined by the number of categories there are for each respectively (e.g. # rows = # teams and # columns = # disciplines).
I don't have any code to show, simply because this isn't so much an error problem as it is a conceptual problem.
My Questions
How would I be able to filter what elements are bound to a cell by their Row/Column? Is this even possible?
i.e. populating the cells of the matrix with elements that occupy both the corresponding row's and column's category.
How do I bind columns and rows to their respective list of categories?
e.g. whenever I add another Column Category, a new empty column will be generated.
I appreciate your help and time!
For your scenario, the better way is using DataGrid to replace.
i.e. populating the cells of the matrix with elements that occupy both the corresponding row's and column's category.
You could use binding way to specific current element in which column and row, but you need to calculate before preparing data source for Grid panel.
whenever I add another Column Category, a new empty column will be generated.
If you use DataGrid, it will generate Column base on your item's new filed. Here is code sample that your could refer.

How to get a column total in a Winforms Pivot Grid control

I need to display the percentage of each cell, of a pivot grid, column against its column total.
So far, I have been checking possible ways to get the columns totals being displayed by the PivotGrid (as I already know how to insert a computed column using expressions) but so far I haven't found a place where these values are available.
I have also considered to handle the CustomSummary or CustomUnboundFieldData events of the PivotGrid but I don't see clearly how can I get the column total from there.
Another approach I have think of is to try to use the PivotCellBaseEventArgs.CreateDrillDownDataSource to get the underlying records of the cell, but then I will not be able to get the column total, as the records returned by that method are only for a specific cell, not for the whole column.
I'll appreciate if you can point out what would be the best approach for dealing with the cell percentage against column total requirement, including any of the previous or maybe another approach I haven't think of.
Also I will be glad if you show me a way of getting the column total from the pivot grid control, if there's any way.
I finally find the way to do this so I am posting it in case anyone else need it...
There is a property on a PivotGridField that allows you to control the way the data is "summarized" (i.e. aggregated). Usually this is set to "as is" or Default but you can change this to support what is called Percentage Modes.
So I just change the PivotSummaryDisplayType, of the field that I wanted to display as percentage, to PivotSummaryDisplayType.PercentOfColumnGrandTotal and that's it.

Prevent readonly columns from reorder

I have a DataGridView that has three read only columns in it and one or several other writable columns. The users have decided they need to be able to reorder the columns. I need a way to allow them them to reorder the writable columns but not the read only ones. The only thing I have thought of is to check if the column that was just moved in the ColumnDisplayIndexChanged event is read only, check it's name and then move it back to where I want it. I don't like that solution. Does anyone have a more elegant solution to this problem?
If column reordering is enabled, the frozen columns are treated as a group distinct from the unfrozen columns. Users can reposition columns in either group, but they cannot move a column from one group to the other.
Does this sound like what you want?
http://msdn.microsoft.com/en-us/library/28e9w2e1.aspx
You could disable column reordering by default, and only enable it when the mouse cursor is over a column that you want to be moved.
Not that I actually tried this, but it's worth a try.

How can I refresh only the visible rows of a data bound DataGridView?

I have a DataGridView bound to a list of custom objects created on the fly. This list is not very large, 5000 items maximum. However, the values of the custom objects change every 50ms and the grid hangs the application while refreshing the values and it ultimately crashes.
My question is: is there a way to "virtualize" the data binding of the DataGridView so that only the rows that are actually seen on the screen are refreshed?
EDIT: I found out why my DataGridView was so slow and it had nothing to do with data binding. So this question is no longer relevant. As a side note, I think the DataGridView already refreshes only the visible rows when a ListChanged event occurs.
A good article on Virtual mode (DataGridView). - http://www.codeproject.com/KB/books/PresentDataDataGridView.aspx#7
Spent quite a while searching this issue and this question kept popping up, so I'll link here the answer which solved my problem: https://stackoverflow.com/a/9348149/674884
I have a DataGridView bound to a BindingSource which is also bound by ComboBoxes and TextBoxes used to edit the data. Every Leave event on the editors had a big lag which was caused by the DataGridView redrawing all it's rows when the data was updated. This happened even when using VirtualMode.
The problem was caused by the AllCells autosize setting of DataGridView columns. Every time a value changed the DataGridView went through all the rows to find the longest string for autosizing the column. After disabling autosizing I realized that even the databound DataGridView draws only the visible rows, so no need to use the VirtualMode.
I think you will want to look into using the DataGridView in virtual mode.
What is stopping you just pulling the visible sub-set of items instead of the full 5000?
I don't know if ListChanged already refreshes only the visible rows.
I can't see any indention in MSDN. I will look into DataGridView implementation later and update.
Anyhow the follow works for me:
int scrollPositionFirst = dataGridView1.FirstDisplayedScrollingRowIndex;
// displayedRowCount -> is our visible rows count
var displayedRowCount = dataGridView1.DisplayedRowCount(false);
// the loop will iterate in the amount of the displayed rows
for (int rowCount = 0; index < displayedRowCount; rowCount++)
{
// scrollPositionFirst is our first visable row
// so scrollPositionFirst is our starting point
var set = (Set)dataGridView1.Rows[scrollPositionFirst].DataBoundItem;
// we update the grid from the first visable(displayed) index
UpdateMainGrid(scrollPositionFirst, set);
// increment index -> this is done because we want to update the next visible row
scrollPositionFirst++;
}

Cleanest way to implement collapsable entries in a table generated via asp:Repeater?

Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of a very large system, so it really wouldn't be wise for me to revise the table structure (the app is filled with similar tables).
This is a webapp in C# .NET - data comes in from a webservice and is displayed onscreen in a table. The table's rows are generated with asp:Repeaters, so that the rows alternate colers nicely. The table previously held one item of data per row. Now, essentially, the table has sub-headers... The first row is the date, the second row shows a line of data, and all the next rows are data rows until data of a new date comes in, in which case there will be another sub-header row.
At first I thought I could cheat a little and do this pretty easily to keep the current repeater structure- I just need to feed some cells the empty string so that no data appears in them. Now, however, we're considering one of those +/- collapsers next to each date, so that they can collapse all the data. My mind immediately went to hiding rows when a button is pressed... but I don't know how to hide rows from the code behind unless the row has a unique id, and I'm not sure if you can do that with repeaters.
I hope I've expressed the problem well. I'm sure I'll find a way TBH but I just saw this site on slashdot and thought I'd give it a whirl :)
When you build the row in the databinding event, you can add in a unique identifier using say the id of the data field or something else that you use to make it unique.
Then you could use a client side method to expand collapse if you want to fill it with data in the beginning, toggling the style.display setting in Javascript for the table row element.
just wrap the contents of the item template in an asp:Panel, then you have you have a unique id. Then throw in some jquery for some spice ;)
edit: just noticed that you are using a table. put the id on the row. then toggle it.

Categories

Resources