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
Related
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'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 requirement to create a "super grid" as part of an application, which will consist of multiple frozen and scrolling panes. The grid also has the requirements that it must support the following features:
Display a datagrid with 100s of rows with “reasonable” scrolling performance
Group by a certain field, collapse/expand grouped
Display any control inside a field, e.g. images, text, combobox, button
Allow buttons and editing of fields as well as read-only mode
Allow multiple vertical split panes (or workaround, multiple synchronised grids)
User column re-ordering with persistence
User column sorting ascending/descending
Dynamic insertion/deletion of columns (column choosing)
4th dimension below grouping – RowDetails template on selected row
Allow Flashing / animated cell/row templates on value update
My initial feasibility suggests that the WPF Datagrid is capable of almost all the requirements above (with heavy templating), however the multiple vertical split panes may not be covered. Below is a diagram of what I'm trying to achieve:
I would like to enquire if anyone has done this before and if so, what grid technology you have used.
Can the above be done in WPF Datagrid? I am aware of Frozen columns however this appears to apply to freezing the first N columns only
Can the above be achieved with multiple grids and synchronizing the Vertical scroll positions?
If so, will this solution still be virtualized?
Are there any third party grids you can recommend to achieve this instead? Please note we will be heavily styling the grid according to in-house branding so it must be flexible and Blendable
Any comments/suggestions appreciated.
Update - Feasibility Investigation Results
I have a working prototype for this using 3x grids and collapsable grid splitters between them.
The scrollviewers are synchronized using the answer from this question.
Selected row synchronized across three grids by binding to a common SelectedIndex property with TwoWay binding.
I will be working on grouping and rowdetails templates next... Thanks to answerers for your points! :)
I've implemented most of your requirements and more with the devexpress wpf grid control. It's not free and there's a bit of a learning curve (their documentation is essential), but it'll save you so much time in the long run...
I've done this with a standard DataGrid with perfect performance and ultimate flexibility, but it requires a sound architecture. Both data and UI need to be virtualized - no control can annul the cost of sorting a large set of data (for example), so if that sorting is happening on the UI thread, the user will notice. If your back-end supports paging and filters, your front-end can virtualize and the user will never know that only 100 rows have been loaded out of their 10000. As they scroll, pages of data are loaded & unloaded in the background and the UI never ceases to be responsive.
However, knowing where you work leads me to suspect that your front-end is the real workhorse...
I'm a bit new to the C#-form app developing and I want know, what's the best way around at making a control that holds a list of horizontal items. In which each of these items are horizontally ruled to it's parent control, contain a thumbnail to the left and a large text block to the right of image and a smaller text block underneath that. So basically this isn't a predefined control I can find in the toolbox. Any ideas?
You could lay this out with Panels in form controls, or with WrapPanel and StackPanel in WPF.
In WindowsForms, I would create a user control that held the correct layout for a single item, then make a list of them at run time.
In WPF I would use a List control, but set the layout template to use WrapPanels and StackPanels.
WPf is the better solution long term if you don't have to coexist with winforms
I was wondering... I have a WinForms System.Windows.Forms.ListView with a bunch of ListViewItems that I'm drawing using the View.List style. Each ListViewItem has a "SmallIcon" that I fetch from the ListView's SmallImageList.
My problem is that the icons are showing too close to the border on the left. I've tried to change the bounds and the ListViewItem's Position property to no avail.
Is there anyway to have some kind of offset to ListViewItems?
The Win32 listview control doesn't have any setting to increase the space between the icon and the label (in any view, not just List). Setting ListViewItem.Position does nothing when the ListView is in List view.
A low-tech solution would be to simply prefix every ListViewItem's Text value with a single space. Slightly ugly, but oh so easy to do.
If you really want to have pixel level control, you will have to owner draw it. As always, if you are doing anything with a .NET ListView, ObjectListView makes owner drawing your items trivial.
As mentioned already, prefixing the text of all your items with a space is a super simple way to add padding. This has a pretty significant drawback, however. Once you do this, you lose the ability to find items in the ListView by simply starting to type their name while the ListView has focus.
Try adding white space to the left of your small images.
If you're using 16x16 images change to 24x16 for example by adding 8 white (or ListView Background color) pixels to the left.
If you are in ListView View LargeIcons then you can postion the text using item.position
A screenshot would be nice for an example to see exactly what you're after.
Funny thing... the Windows Explorer uses the ListView to display files and folders. i usually run my view in Report or Detail mode. i just switched it to List view mode and see the exact problem that you're describing! Yikes. Might be a bug with the Win32 object and that particular view type!
A quick workaround might be to use a Report style for the ListView with a single column or perhaps implement something yourself. The FlowLayoutPanel in .Net would work very nicely as a starting point for a custom list view.
As you are using the View.List style, I suspect you'll either need to implement some custom drawing or consider padding your images. You could also look at overriding the ListView control and manipulating it's bounds by overriding SetBoundsCore or SetClientSizeCore (or similar).
However, if the ListView were set-up for View.Details view, this could be done using the ListViewItem.IndentCount property:
The IndentCount property can be used
only when the View property of the
containing ListView is set to Details,
and the SmallImageList property of the
ListView is set. Source:MSDN
If you set the StateImageList property you can add a space of 16 px before the icons. I think you can adjust this additional space by loading an image with matching width as first entry into the StateImageList. But I have not tested this.
This thread discusses the opposite problem.