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.
Related
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
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 have a DataGridView with a DataSource and I want the data to be displayed on the entire width of the control with the auto-computed width of each column. The exception is the first one which should always have 100px.
I handled the Size event, I set always the fist column to have 100px and it works, but only if I manually resize the grid.
Is there any way I can do this automatically, right after the DataSource was set?
I tried to invalidate the control, I set (again) the autofill (and not only) flags of the grid, but no luck. Did anyone managed to do a similar thing?
When editing the columns, there is a property called AutoSizeMode. Im wondering why you are trying to handle it yourself. Just set all columns except the first one to AutoSizeMode = AllCells and then give your first column the width of 100px. Should do it shouldnt it?
Bonus: You can even set one of the columns to Fill in AutoSizeMode. Would look a bit better as your table is taking the full width.
If I missed the point please correct me...
I have several list view controls, each with many columns that I'd like to have the columns can't be resized too small passed the label size.
I know I can handle the event for column width changed but I don't want to have to do this over and over again, and all columns are different length of text.
The Windows Forms ListView can be a source of frustration. I've heard good things about ObjectListView which is an open source replacement for the ListView that has an assload of features. Back when I was using Windows Forms I wish I had known about it.
Anyhow, here's a link that describes a feature that should do what you want.
http://objectlistview.sourceforge.net/cs/features.html#more-control-over-column-width
Is it possible to specify a size for the grid view cell when it is in edit mode. The size should be in terms of letters (like we have maximum size for a text box) and not in pixels. My requirement is that user should be able to input not more than 100 characters in the cell when he is editing it.
I want to avoid validating after the user updates as it will get inconsistent with the rest of the site.
Any other work-around is much appreciated.
Any inputs???
Thanks :)
You probably need to use TemplateFields and define EditItemTemplate where you set the maximum length of textbox. Or you could use validation and give error if the input is too big.