1

do you guys know a .net ListView-Replacement which can be highly customized? I am developing an app which is similar to a "todo" list. I want to be able to customize almost every visual detail of the list so I get something like this:

ListView

I want also to be able to reorder items by mouse + I need drag&drop. If you don't know any ListView, maybe you know how I could make my own listview like this one from scratch?

Thanks for your ideas!

3
  • I'm assuming you don't want WPF?
    – user541686
    Mar 20, 2011 at 18:48
  • WPF, Silverlight, or WinForms? Mar 20, 2011 at 18:48
  • if it is possible with WPF, why not. :) but I have no idea of wpf g - I want to pay and buy a customizable listview insteed of sitting for months and trying to learn wpf ;) so yes, I prefer winforms.
    – MilMike
    Mar 20, 2011 at 19:01

3 Answers 3

5

Using a flowlayoutpanel control as the container, and then create a usercontrol that is the listitem, you are half way there. The usercontrol can have whatever look you want and will act as an listitem in the flowlayoutpanel. Then we have the drag & drop. Following this code (Orginally from this example: http://www.codeproject.com/KB/static/DragDropFlowLayoutPanel.aspx ) you'll add drag and drop of items in your flowlayoutpanel:

First create a new windform-solution, then create a usercontrol with only a label in, we use it as an example of your special listitem-control. Name the control MyListItem. Paste this code in the usercontrol to make it drag and droppable:

Public Class MyListItem
    Public Property AllowDrag() As Boolean
        Get
            Return m_AllowDrag
        End Get
        Set(ByVal value As Boolean)
            m_AllowDrag = value
        End Set
    End Property
    Private m_AllowDrag As Boolean
    Private _isDragging As Boolean = False
    Private _DDradius As Integer = 40
    Private _mX As Integer = 0
    Private _mY As Integer = 0

    Public Sub New()
        InitializeComponent()
        Margin = New Padding(0)
        AllowDrag = True
    End Sub

    Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
        Me.BackColor = Color.Navy
    End Sub

    Protected Overrides Sub OnLostFocus(ByVal e As EventArgs)
        Me.BackColor = Color.Transparent

    End Sub

    Protected Overrides Sub OnClick(ByVal e As EventArgs)
        Me.Focus()
    End Sub

    Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
        Me.Focus()
        _mX = e.X
        _mY = e.Y
        Me._isDragging = False
    End Sub

    Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
        If Not _isDragging Then
            If e.Button = MouseButtons.Left AndAlso _DDradius > 0 AndAlso Me.AllowDrag Then
                Dim num1 As Integer = _mX - e.X
                Dim num2 As Integer = _mY - e.Y
                If ((num1 * num1) + (num2 * num2)) > _DDradius Then
                    DoDragDrop(Me, DragDropEffects.All)
                    _isDragging = True
                    Return
                End If
            End If
        End If
    End Sub
    Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
        _isDragging = False
    End Sub
End Class

Then place a flowlayoutpanel (flowlayoutpanel1) onto the main form in the app.

Add this code to the form, it will fill the flowlayoutpanel with listitems you can drag and drop:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        FlowLayoutPanel1.AllowDrop = True
        For p As Integer = 0 To 50
            Dim listitem As New MyListItem With {.Height = 50, .BorderStyle = BorderStyle.FixedSingle}
            listitem.Label1.Text = "Item:" & p.ToString
            FlowLayoutPanel1.Controls.Add(listitem)
        Next
        AddHandler FlowLayoutPanel1.DragEnter, AddressOf flowLayoutPanel_DragEnter
        AddHandler FlowLayoutPanel1.DragDrop, AddressOf flowLayoutPanel1_DragDrop        
    End Sub

    Sub flowLayoutPanel_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
        e.Effect = DragDropEffects.All
    End Sub

    Private Sub flowLayoutPanel1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
        Dim data As MyListItem = CType(e.Data.GetData(GetType(MyListItem)), MyListItem)
        Dim _destination As FlowLayoutPanel = CType(sender, FlowLayoutPanel)
        Dim _source As FlowLayoutPanel = CType(data.Parent, FlowLayoutPanel)
        If sender.Equals(data.Parent) Then
            Dim p As Point = _destination.PointToClient(New Point(e.X, e.Y))
            Dim item = _destination.GetChildAtPoint(p)
            Dim index As Integer = _destination.Controls.GetChildIndex(item, False)
            _destination.Controls.SetChildIndex(data, index)
            _destination.Invalidate()
        End If
    End Sub

Now you can start the program and test. You now have a "listview" that can have customized controls in it and lets you drag and drop items to change the items order.

Credit goes to P.Sandgren, for the drag and drop of items in the flowlayout panel:
http://www.codeproject.com/KB/static/DragDropFlowLayoutPanel.aspx

0
3

Use WPF ListBox and an ItemsTemplate :) check out http://msdn.microsoft.com/en-us/library/ms752347.aspx

3

You can try the ObjectListView (http://objectlistview.sourceforge.net).

You can get rich features such as these:

Sample1
(source: sourceforge.net)

Sample2
(source: sourceforge.net)

Sample3
(source: sourceforge.net)

One thing to know is that you'll have to be prepared to do a lot of things in the code-side instead of the usual designer view in order to get the desired level of functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.