The title pretty much describes what I am looking for. I have found answers that are close but not quite what I need. I am hoping someone can explain how to do this or point me in the right direction.
Current setup:
I have multiple user controls. Each contain a grid that has 5 rows and 3 columns. First row definition is set to Height="Auto" and the rest are Height="". First column definition is set to Width="Auto" and the others are set to Width="". I do not want the first row and first column to ever change size but I would like to have the rest of the grid scale.
Question:
I am trying to create a window, which contains a grid, that will dynamically size. The grid contains user controls stated above and each row and column in the window is set to *. I do not want any element in the window to size below what is required for the inner controls (i.e. I do want a button control change sizes but it should never become smaller then Auto width or height). Is there a way to allow for this scalability but do not get any smaller then what the controls requires (ideally within the xaml)?
I don't remember the exact CSS syntax, but I was hoping xaml had something similar to the way CSS sizes content equal to the size of characters on the screen (i.e. Min-Width: 1.5m;)
If you wanted the first row and column to be a static size then don't set them to auto, set the actual size then for the rest of the columns/rows you could use * so they all remain equal
Related
I have two elements in the form, two GridViews.
Both of them are aligned horizontally at the same level.
When my form is resizing, I want both of them to change their width/ height according to the form size.
The problem is, if I try to anchor them, they kinda overlap at some point and I want to avoid that.
My question is, can I anchor one Grid View to the other Grid View and not to the form?
A solution can be a TabelLayoutLabel, but i don't really want to use this.
My question is, can I anchor one Grid View to the other Grid View and not to the form?
no you cannot, and if you could that would be bad practice.
the anchor property description by microsoft:
Gets or sets the edges of the container to which a control is bound
and determines how a control is resized with its parent.
a dataGridView is not a container it's a control.
it sounds like you should use a table layout panel, that would give you the best results.
search for it in the Toolbox:
make sure you set its property to Dock = fill, where ever you want, and
,
next. in the property of the table view, you enter Edit Rows And Columns
and set each column to the percentage that you desire
add your grids to each column,
and set each one's 'Dock' property to Fill, and there you go
you can undock the tableLayoutPanel and change its size,
Hope that was helpful
The Source of the Problem
I have a situation where an old WinForms grid was placed in a PageView, then generates another page and sets it active if you click one of the rows. The original idea was that the second PageViewPage's grid would contain "detail information" and that the original grid would bear a summary, but over the years more and more data from the detail page has been added to the original grid. This turned a 6-column GridView that needed to be stretched to fit the screen into a 20-column GridView that causes a lot of scrolling to happen, especially in our manufacturing plants where some of the oldest machines still have 1024 x 768 CRT's.
The Problem
I'm developing on this screen, now using Telerik controls. My task is to find a way to display all of the data from both pages in the one grid, but with little-to-no horizontal scrolling required. After appending the few fields which were not already duplicated and combining related data (i.e. Account Number and Account Name being one hyphenated column with word wrap instead of two), I've got 19 columns. 1/3rd of the grid is still offscreen.
SO far I have:
Combined like data (as above)
Reduced font sizes slightly
Changed the BestFitColumnsMode to DisplayedCells
Reduced all columns which had a fixed number of characters to display to the right size to display only those characters
Abbreviated column names that are larger than their potential data and replaced with a symbolic icon on CheckBoxColumns
Replace all written-out "true" - "false" TextBoxColumns with CheckBoxColumns
Now I'm stuck. I considered dropping the column headers and instead making a bunch of RadGridView pairs for each line, effectively "wrapping" the grid, but that would rob me of the sorting and grouping features we actually need which are provided by Telerik out of the box. Is there a "best practice" for situations like this, or perhaps a feature of GridView or RadGridView I'm missing?
One option has already been ruled out; I can't replace this with a list of UserControl that contains labels (i.e. "ID: xx" instead of an ID column with xx in a cell) or similar. Column headers are required by the project.
I would like to simply enable autosizing on my datagridview (or similar behavior). I want some columns to grow and fill all available space. However, I also have some columns that I want 100% fixed and to not grow at all, and I can't get this particular behavior.
Unfortunately, no matter what the fill rate is, I can't figure out how to lock the columns I don't want to change. So far, I have tried:
Setting FillWeight to be extremely small on the columns I want locked. Unfortunately, this just causes the column to become sized too small off the bat, regardless of its initial width setting.
Setting Resizable = DataGridViewTriState.False only prevents the user from changing the size of that column. It still resizes automatically when I change the window size.
Does a solution exist? If I can't find one, I'll need to write up my own implementation, triggered using DataGridView.Resize I take it.
I see, MinimumWidth needs to be leveraged as part of the solution. FillWeight = float.Epsilon, MinimumWidth = 50 seems to do the trick.
I'm building a Windows Store App that uses a GridView to show a list of items (basic, out of the box template). I would like to know if I can get the total width that all the items take up.
Right now I'm taking the number of item columns and multiplying it by the total width of one of the items. This is working, but it requires that my code behind knows way too much about my view. I'd like to find the one property that has the width and just bind to it.
Thanks for any help!
Here is the code that I have to get the column width of the GridView
(itemGridView.ItemContainerGenerator.ContainerFromIndex(0) as GridViewItem).ActualWidth
I don't have a good way to get the number of Columns, so that would also be helpful
The ActualWidth property of the GridView should contain the information you are looking for.
If not, you could try to call Measure on the gridview to let it perform the required layout calculus and output its desired Size.
I have a control that inherits from Grid, it is a grid of hexagons that are generated dynamically according to the properties.
each of the hexagons is a button and a child of the Grid, and they have a style that displays them as hexagons.
what I want is for the grid to change its size according to the total size of the hexagons.
(I can calculate the exact size needed, but I don't know how to set it).
Basically you've got several options. A simple one is calculating the size yourself and assigning to the Grid's Width and Height.
A more elaborate solution would be to ask yourself a question: which layout is needed for my items? There are some standard containers which do the layout themselves and can grow/shrink with the content. For example, if your objects are just aligned in a line, you can go for StackPanel.