Custom controls in a row of a list view - c#

I want a list view control (or any list like control) in which each row (item), not only has text, but also some other controls. For example, each row (item) in my list view is composed of a checkbox, button, a slider, a image and a label. I tried the corresponding renderer classes (CheckBox renderer) in the owner drawn event, but i am not able to handle the events (as they are just used to render the control on the screen).
I tried to search for solutions, but in vain. So I have decided to have a panel and then create objects of those controls in runtime, for each item and add it to the parent panel. Is the solution ok? I feel this to be process costly. Help me out !!
Note, I am using WinForms and no DataTemplates or WPF stuffs

Maybe this helps?
http://www.codeproject.com/KB/list/extendedlistviews.aspx

Related

How to implement panel with features of ListBox And FlipView in WPF

I'm am not good enough in WPF, so I'd like to ask for any advice how to implement panel layout something link displayed on image below:
So, the main purpose is to display a collection of items with possibility to select a single item, which should be moved to the first position (probably with animation) and then another item template should be applied to that container (it is bigger than other items in the collection). The list doesn't have to be infinitive, so just like a simple ListBox.
For me it looks like a FlipView but with a few items, which are neighboring siblings of the selected one and are also visible in the panel's viewport.
Please, advice me how to implement such a panel, or if you have seen something suitable, please, provide a link to the source.
You need to create your custom panel using User control.
Here is one example which is similar to your requirement.

Displaying a collection of controls in Windows Forms

I want to display something like the following :-
Each row is about a process (information like PID, Parent etc.). User can check the checkbox and click Launch button to get some dynamic details about that process.
The problem is that CheckedListBox control doesn't allow more than one columns and other controls like ListView (which allow multiple columns) don't allow controls like checkbox to be embedded in a columns.
I want to know if there is a control which will allow me to have a list of custom controls where each custom control contains a checkbox, Some Text and Some Dynamic Text.
How can this be achieved in Windows Forms? Thanks in advance.
You can use either of these options:
DataGridView (Example)
You can use DataGridView to show multiple columns of different types, including TextBox, Label, CheckBox, ComboBox, Image, Button, Link. You also can customize appearance of the grid by custom painting or adding new custom column types.
UserControl
You can create a composite control or UserControl containing any other controls which you need and use it as a row template, then you can show all rows by hosting multiple instance of that user control in a Panel or FlowLayoutPanel.
TableLayoutPanel (Example)
You can use a TableLayoutPanel containing multiple columns and rows. Each cell of TableLayoutPanel can host a control.
DataRepeater
You can use a DataRepeater control to create a row template and show a list of rows using that template.
Example 1 - DatGridView
If you want to use data binding and show specific controls including TextBox, Label, CheckBox, ComboBox, Image, Button, Link a row, DataGridView is great. It's customize-able and you can add some other different column types or customize painting of the grid or benefit from wide range of useful events for validating and so on.
In following image you can see a DataGridView with RowHeaderVisible and ColumnHeaderVisible set to false to act like a List of fields without header:
Example 2 - UserControl
If you need custom control to host more complicated controls or having more control on components or show them in a different layout than columns, you can create a UserControl hosting your components, then:
If you only want top-down flow, Use a Panel and add your user control to it with Dock property of control set to Top.
If you may want flows other than top-down Use a FlowLayoutPanel to add instances of your control to it.
Create a UserControl
Add instances of it to your Panel or FlowLayoutPanel
You could use the TableLayoutPanel container.
I want to know if there is a control which will allow me to have a
list of custom controls where each custom control contains a checkbox,
Some Text and Some Dynamic Text.
One option could be that you create the following as a separate user control,
...and as container control use container like FlowLayoutPanel and keep adding the user control into the FlowLayoutPanel.
Make sure that the direction of FlowLayoutPanel is set TopDown
this.FlowLayoutPanel1.FlowDirection = FlowDirection.TopDown;

Getting the Selected Item among items present in Grid

I am implementing a Media Player application using WPF. I want to display a List Screen where the user can select the video from a list.
I want to display the videos in a list horizontally(without scrollbars so not using ListView) where each item consists of a thumbnail, title and duration.
Now I also want to obtain which item was clicked on so as to play the correct video. I tried to display the items in a WrapPanel which sufficed for display but doesnt have a SelectedIndex property.
Will a Grid be helpful in this regard? If yes then how do I obtain which item was selected in the Grid?
Use a ListBox.
WPF UI elements keep their appearance separate from their functionality. If you want a list of items where you can select one, use a ListBox. If you want to customize how it looks, simply change its Template.
Grid, WrapPanel, StackPanel and the like are just Panel UI element which are used for Layout. They don't derive from Selector and thus don't have any item selection features.
Since you didn't post any relevant XAML in your question, I'll not post any relevant XAML in my answer.

Dashboard controls in Winforms

I am working on a WinForm based applications(Yes I don't know WPF) and want's a dashboard like panels in it. Picture given below
Each panel will have a title and records from Database and some action controls. How could this be achieved? I don't want to use GridControl as I don't want to show Excel like spreadsheet here. How could this be achieved?
It sounds like you want to make a UserControl, possibly coupled with an automatic layout panel like FlowLayoutPanel.
Simply speaking, you would create a UserControl with whatever properties and events you require (i.e. in your example you might have a Title property and a Data property), and any events you need to respond to (e.g. you might have a button that you provide a wrapper event for). Then you can add the control to your existing form as you would any other standard control.
As far as displaying data in list form goes, one suggestion is to use a Panel and dynamically add Labels to it. Another idea could be just a simple Label with line breaks in the Text.

What is the best way to embed controls in a list/grid

I have a table of about 450 rows that I would like to display in a graphical list for users to view or modify the line items. The users would be selection options from comboboxes and selecting check boxes etc.
I have found a listview class that extends the basic listview to allow for embeding objects but it seems kind of slugish when I load all the rows into it.
I have used a datagridview in the past for comboboxes and checkboxes, but there was a lot of time invested in getting that up and running...not a big fav of mine.
I am looking for sugestions how I can do this with minimal overhead.
thanks
c#, vs2008, .net 2.0, system.windows.forms
If you have a complicated set of controls for each row, this is the simplest way to do it. However, it won't act like a listbox; you won't be able to highlight your rows or navigate with the keyboard.
Create a usercontrol with public property to point to your row
Draw a panel on your form - you will add instances of your 'row' usercontrol at runtime to this panel.
Set the panel to autoscroll (also set property to make the active control scroll into view)
Set the panel's Anchor property so it sizes w/ the window
You can set the form's max/min size properties so the full usercontrol row always shows (have to do to prevent horiz. scroll bar in panel)
Have a routine to add the rows
In a loop, create new usercontrols, set their properties, including the row in the datatable
Also, set the .Top property to the panel's .controls(pnl.controls.count-1) for all but the first one you add
Very simple, allows complicated 'rows', gets the job done. There are better ways to do this if you want listbox-like functionality without coding it yourself, but you may not need that.

Categories