winforms listview - make first column always visible? - c#

I have an application (winforms, c#) that displays data in a Listview in a very usual way - the first row is headers, the first column in each row is header and the following sub-items is the data itself.
I want the first column (the headers columns) always visible and the horizontal scroll to affect the other columns only.
i don't think it is possible in winforms listview (am i wrong?). Hence, i'm thinking to split the listview to two listviews - one for headers and the second for data. In that case, i need to connect the vertical scroll bars - a task which i find to be harder than i've expected.
Am i taking a wrong path (e.g. would it be easier to use a different control)?
If not, any pointers on how to implement it?
Note: Winforms Listview has poor API (e.g. no scrolling event) and is known as buggy, so i'm looking a working sample rather than MSDN links...
Thanks

As already noted the DataGridView supports this behaviour, but nobody told how this will be done:
To enable this feature simply set the Frozen property of a column. Further informations can also be found in this How to: Freeze Columns in the Windows Forms DataGridView Control.

I think you have to try to use the DatagridView instead of the listbox. As far as I know, the DataGridView supports this.

Did you try using DataGridView instead?
Edit:
In case you run into problems with setting row headers text, take a look at this post (basically, you set row header text upon item being added to grid).

Related

ListView with headers and ItemTemplate

I'm trying to achieve a view similar to this ((Sub)(Sub)Item names not being part of the view - they show how the source data is structured):
EDIT:
As per comment, I'm adding an example of how I want to render the data (2 items):
That is, I have bunch of Items which I want to render in customized way. Those have SubItems that start being part of the grid (possibly spanning multiple cells). And those have SubSubItems with more data to put inside the grid (each on one row).
I want the data that belongs to a grid, to be aligned according to my Column headers.
I manged to make this work using a ListBox with ItemTemplate set to DataTemplate defined in resources. Going down 3 levels of hierarchy, using Grids to layout the content. There were 2 issues with this:
Aligning the data in grid with column headers. I managed to solve this using top level grid as column headers and IsSharedSizeScope/SharedSizeGroup. But it wasn't very nice solution and the alignment proved difficult to achieve.
Drawing borders around cells - since it wasn't just one Grid, but multiple within each other, borders would not connect nicely or have different thickness. I didn't manage to solve this so far.
I tried using ListView instead of ListBox, with GridViewColumn, but that disabled the ItemTemplate rendering.
Is there a way to use both? Or some other way to add the Columns with their default nice style and on-the-fly re-sizing capabilities? What about the cell borders?
Or am I looking at it entirely wrong and I should use different approach altogether?
I did try using DataGrid but that seemed even worse approach.
Note: I need virtualization - working with lots of items.

Create a custom Data Grid from Silverlight

I'm watching at this page:
http://leeontech.wordpress.com/2010/02/01/summary-row-in-datagrid/
But they're using silverlight. I'm trying to create that user control to use it in a WPF C# application. I mean, not using Silverlight. But I can't find the namespaces: GroupHeader
I'm having a hard time with this. Thanks in advance.
Okay listen, you can totally do this, and in some scenarios I even recommend it.
Using a CollectionViewSource you can easily group your data. In the HeaderTemplate you can even use an Expander (or make your own) and get the animation you might be wanting. Here's a link to a sample of this: http://jerrytech.blogspot.com/2010/06/wpf-data-presentation-step-by-step.html
Using an ItemsControl, you can easily present your groups and details. In the ItemTemplate you can use styles make this look like a grid (if that is really what you want). You can also shift the style based on the type if your collection has more than one type of object in it (eat that datagrid!).
You can wire up your column headers (which will really be custom objects, right?) and handle all the sorting and stuff like that. They will look just right! Not like datagrid WinForm column headers!
Here's what's hard (not impossible, but more coding).
User-resizable columns.
User-rearrangable columns.
New record using bottom, empty row.
Paste from Excel (doesn't work right in datagrid either).
Select Row, highlight Column header.
That's it.
In lots of situations, this is really nice.
For the most part, I cannot stand the datagrid. Too restricting on UX.
I don't think you're not going to be able to get a silverlight control working in WPF.
Adding a footer row to the WPF datagrid is something a lot of people have complained about; it's ridiculous that it wasn't included out of the box.
See this thread from MSDN
Having been through this myself, your best bet will probably be to bite the bullet and use a third party control. It sucks, I know.

How to make popup window auto populate with contents in cell

I have a data grid displaying results from a sql database. What I want to do is make it so that when I double click on a cell in the datagrid, a new window appears where that cell can be edited. I also would like to have all the info for that cell to be autogenerated into editable fields when the cell is double clicked. Any help or links to tutorials is appreciated. Thanks.
Try this DataGridView.CellDoubleClick Event
Did you consider using data binding? Simply put, you can bind your items list to DataGrid, and current item (eg. selected/double clicked) to your edit form's controls (TextBox, Label and whatever else you might have there).
Here are good starting points for windows forms: #1, #2. They cover problem you're facing. You can find data binding tutorials for ASP/WPF easily too, but especially first link covers entire concept pretty well.

How do I display a DataGridView within a cell of another datagridview in C# forms app?

How do I display a DataGridView within a cell of another datagridview in C# forms app?
How would I have to handle Sorting & value changed if this possible?
That is the only way I can display data to make some sense.. Think of it like I have a task column and dates column. Under the dates column I have a list of things to be done. These date columns are dynamic & there might be multiple date columns
That sounds like a difficult interface to use, have you considered some kind of tree control?
If you're determined to use data grid views, look at customizing data grid view columns and cells. You need to declare custom subclasses for the column and cell behaviour that you want. I don't know if it's possible to do what you want, but that's where I would start.
This is a suggestion since what your asking I do not think is possible with the built in DGV of .NET.
Using custom controls made by professional companies that provides a DataGrid with the capability of hierarchical data. For example a row can be expanded to show multiple entries (the multiple entries can be an entirely different table containing completely different columns even). Here are a few options that you can check out.
Infragistics WinGrid
Component One
There are a few other places/companies that make great .NET component packages that provide added features to the existing .NET components.
http://blogs.msdn.com/markrideout/archive/2006/01/08/510700.aspx
Found a link where hierarchichal datagrid is implemented.
Now, I have to either modify the control, or settle for hierarchichal gridview!
Hope this helps someone. Will update later

How to achieve multiple grids like the SQL server Results pane

I'm having problems with my project once again :(
The front end is C#
I need to support multiline querying like MS SQL server and when these queries are executed, naturally there are going to be multiple result sets.
Getting the datatables respective to the results is not a problem, but how do i make it appear like its done in MS SQL server. One result set below the other and with a scroll bar?
Should i bind it to a datagrid? If so how can i bind multiple tables to a datagrid ? and will it generate the scrollbars and the columns automatically?
If i am not clear, please let me know and i'll try to be more clearer.
ps: If anyone knows how this can be done with the XtraGridControl in devexpress that would be awesome ! :D
you can set a panel with scroll bars on your form and add programatically number of datagrid depend of number of data source. Just add datagrid control to the defined panel.
The control you probably want is System.Windows.Forms.FlowLayoutPanel (see FlowLayoutPanel#msdn)
It is available from .NET v2 and greater.
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
....
// for each result...
flowLayoutPanel1.Controls.Add(newGrid);
I have used it before to achieve a similar effect. I have not however tried to re-size the items within it, they were fixed in height (re-sized width-wise to fit the parent).
You should be able to create each XtraGridControl instance with the required data and add it to the controls as above.
PK :-)
SQL Management studio doesn't display all the results in a single grid unless it's a UNION query. Appending multiple grids to a single scrollable pane is the right way to do it, unless you want to break them off into individual tabs.

Categories

Resources