I am creating Windows Forms application using C# .NET in Visual Studio 2010.
I populate data to a ListView from a Excel file. Now I wanted to select a particular cell or list of adjacent cells vertically. I have attached a sample image here:
I wanted do something like this inside a ListView.
I need suggestion from you to understand the methodology (like what are events I should use, what properties of the ListView I should change to do this, etc.)
I appreciate any help you can give.
A ListView control is a poor substitute for a grid control. You can simulate this by tinkering with ListViewItem.UseItemStyleForSubItems = false, the sub-item's BackColor property and ListView.HitTest() but that isn't any fun. Consider DataGridView or one of the many spreadsheet and grid controls available from 3rd party vendors.
Related
In a Windows 10 UWP application I'd like to bind a collection of simple objects to a GridView or ListView and have the GridView or ListView autogenerate the columns based on the properties of the object rather than having to manually declare the columns and {Binding Path=SomePropertyName} on a TextBlock in the XAML.
This doesn't look possible.. is it?
Is there a different type of control other than GridView or ListView that will allow this behaviour?
Note: This is not WPF
TL;DR: This is not possible out of the box with the GridView or ListView controls.
In UWP a GridView is:
A control that displays data items in rows and columns.
The ListView is quite similar but only shows the items stacked in 1 dimension, by default vertical.
The DataGrid control (what this is typically called) is currently (as of SDK build 14393) not available in the default control set. With "some" effort you could write your own control for this behavior.
There are however multiple 3rd party solutions available, just google/bing for UWP DataGrid. Here are some of them:
MyToolkit.Extended NuGet package, more info on their GitHub page.
Libraries that might need a paid subscription/license:
SyncFusion
ComponentOne
Infragistics
You might find even more alternatives.
Can you write it in c# instead of xaml? Maybe it would be possible then, as long as you can access the container (gridview or whatever you use) beyond the constructor of your class. I'm not entirely sure if you can generate a new grid and switch on the fly but you could test it easily.
I have a C# CLI program that scans for missing Windows updates and writes them to command line or serializes them to XML depending on the flag passed in. I'm trying to build a WPF component to this but am unsure of a few things. Specifically I'd like to write all missing updates to a grid in the center of my WPF main window. The appearance would be something like this (with gridlines between the fields):
NAME SEVERITY DETECTED
Security Update for Windows 7 (KB1234567) Important 3/9/2014
Security Update for Windows 7 (KB7654321) Critical 3/9/2014
My specific questions:
What type of control would I need to add to the window to house this data?
How do I send the data (detected missing update names and properties) to the grid for display?
How can I set the control so that it is collapsed (or invisible) when no missing updates are detected?
Will I need to add a scrollbar to the grid or will one display automatically?
Apologies for the simple questions. I'm really just looking for some examples to get started, and I haven't been able to find anything thus far that meets my needs.
What type of control would I need to add to the window to house this
data?
DataGrid control is what you are looking for.
How do I send the data (detected missing update names and properties)
to the grid for display?
Bind ItemsSourceof DataGrid to ObservableCollection<T> where T will be class containing data with properties Name, Severity and Detected.
How can I set the control so that it is collapsed (or invisible) when
no missing updates are detected?
Add a DataTrigger to check if ItemsSource collection contains no data, collapse the visibility.
Will I need to add a scrollbar to the grid or will one display
automatically?
DataGrid internally use ScrollViewer. No need to add explicitly.
Refer to the dataGrid samples here and here.
As an alternative DataGrid can offer ListView control, it will be little "easier" than the DataGrid, he also supports the ability to sort columns. For him also need to bind a ItemsSource collection to display:
The ListView control provides the infrastructure to display a set of data items in different layouts or views. For example, a user may want to display data items in a table and also to sort its columns.
Example in MSDN.
Little add some notes to the wonderful answer of #RohitVats, all that has been said about DataGrid also applies to ListView:
How can I set the control so that it is collapsed (or invisible) when no missing updates are detected?
In this situation, I advise you to adhere to the principle of MVVM. Use Binding and Commands to create an independent application. You want to create property (for example IsEnabled) in Model / ViewModel and use bindings to set them in the View, in order to avoid apply directly to the Control. WinForms style app or "regular" applications creates a strong connection between logic and UI, which subsequently impedes further change and application maintenance.
I am looking for a control that will show a list of Layers with a checkbox toggling its visibility and a thumbnail for its preview.
What control do I use in c# win forms?
How to go about custom rendering the individual list cells?
In java I would have used a JTable and rendered each cell according to the type of each cell. How do I do the same in c#?
A ListView should do what you need.
Edit: In particular enable "Checkboxes" in the properties. You can look into Owner Drawing for more rendering functionality.
I need a multi columned Treeview for an app I am writing, I was wondering if anyone knew of a free working (in Vs-2010) multi columned Treeview.
There are a number of sample controls to be found around the web:
TreeViewAdv for .Net
TreeView with Columns
ContainerListView and TreeListView
But the all-time favorite is probably the ObjectListView, which provides an expandable, multi-column ListView, along with many other incredibly handy features:
You can use this example here or download this control
Try this Microsof TreeListView WPF control
http://msdn.microsoft.com/en-us/library/vstudio/ms771523%28v=vs.90%29.aspx
You can do an illusion to the user in the user interface.
Drag a listview and drop this over the treeview which was already placed in the form.
Create columns in the listview as you need.
Set the 'HeaderStyle' property to 'Nonclickable' and 'Scrollabe' property to 'False' of the listview.
Set width and location of the listview as it fits to the treeview.
i like to split/merge the datagridview in c# windows form application .is it possible in c#.
The DataGridView does not have any support for merging cells. You can custom paint content across cells, but apart from that you would have to do a lot of work and custom coding to produce merged editable cells.
Currently i don't fully understand what you like to split and merge.
But if you like to show the composition of several things (e.g. an image and some text) in one column you can take a look into this how to build a Custom NumericUpDown Cell and Column for the DataGridView Control.
Instead of using the NumericUpDown you just have to create your own UserControl that holds all the merged data and replace in the example the NumericUpDown against your own control.