|
Hi,
Great control, am really glad i came across this control, with it's awesome drag and drop features.
I'm needing to colour sub items, but when trying to use 'li.UseItemStyleForSubItems = False' Subitems show in white text.... they are there in the list, but not visible.
Any idea ?
Thanks
T
|
|
|
|
|
Hi SSDriver2112,
Really nice control together with your other control, the gTrackBar which I superbly love and have used in my application (whenever I wanna see a new control you built, I actually check if there's a 'g' as the prefix character...hehe, kinda like your "signature" in Codeproject).
Anyway, wanted to ask sir if you can help me out with some nicely detailed code samples and/or implementation of a listbox with ItemMouseHover support, DragAndDrop support and Ordering of items within the Listbox. If at all you can actually implement any of these features amongst the three, especially on ItemMouseHover support, I'll superbly and highly appreciate your support as I've already customized the Listbox control to look as I prefer; I know you can highly assist me due to your great experience with the .NET Framework and all its sweetness.
Yet, I say thank you for your amazing work, time and expertise! You're truly bringing change to us as .NET developers across and beyond! Thanks.
|
|
|
|
|
Thanks Willy,
The ListBox does not have an ItemMouseHover Event and the MouseHover will not fire while dragging. The ListBox does have an IndexFromPoint function that can be used in the DragOver event. I would suggest just using the gListview with one column to look like a ListBox, but if you really need a ListBox try this. Create a new Form and put one ListBox and one TextBox on it and add the Code.
Note: You can go here to see all of my articles (so far). SSDiver2112 Articles [^]
SSDiver2112
Public Class Form3
Private HoverItem As String
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim list1 As String() = New String() {"AAAAAA", "BBBBBB", "CCCCCC", "DDDDDD",
"EEEEEE", "FFFFFF", "GGGGGG", "HHHHHH",
"IIIIII", "JJJJJJ", "KKKKKK"}
ListBox1.Items.AddRange(list1)
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As Object,
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragDrop
If e.Effect = DragDropEffects.Move Then
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
Dim p As Point
p.X = e.X
p.Y = e.Y
Dim intInsertAt As Integer =
ListBox1.IndexFromPoint(ListBox1.PointToClient(p))
If intInsertAt = -1 Then
ListBox1.Items.Add(e.Data.GetData(DataFormats.Text).ToString)
Else
ListBox1.Items.Insert(ListBox1.IndexFromPoint(ListBox1.PointToClient(p)),
e.Data.GetData(DataFormats.Text).ToString)
End If
End If
End Sub
Private Sub ListBox1_DragEnter(ByVal sender As Object,
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListBox1.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListBox1_DragOver(sender As Object, e As DragEventArgs) Handles ListBox1.DragOver
If e.Effect = DragDropEffects.Move Then
Dim p As Point
p.X = e.X
p.Y = e.Y
Dim intInsertAt As Integer =
ListBox1.IndexFromPoint(ListBox1.PointToClient(p))
If intInsertAt = -1 Then
HoverItem = String.Empty
Else
HoverItem = ListBox1.Items(ListBox1.IndexFromPoint(ListBox1.PointToClient(p))).ToString
End If
TextBox1.Text = HoverItem
End If
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles ListBox1.MouseDown
ListBox1.DoDragDrop(ListBox1.Text, DragDropEffects.Move)
End Sub
End Class
|
|
|
|
|
Oh, nice, it actually worked right, the Drag & Drop plus items' ordering was perfect...
And I'll actually go by what you've said, that the Listbox does not have ItemMouseHover Event and the MouseHover will not fire while dragging through the Listbox as it's very true, unless really hard-coded. What I actually wanted was to implement a list of items and sub-items, but then the sub-items would be previewed right down below the title, for example:
---------------------------------------------
first item
some information about this item
additional information like address, email...
---------------------------------------------
second item
some information about this item
additional information like address, email...
---------------------------------------------
third item
some information about this item
additional information like address, email...
---------------------------------------------
That is my target style of list (plus icons can be embedded to the left just like the normal listview type) as I'm actually building a simple and quick notes managing app with vb.net that will enable users to view the note's name, the date of modification and other related information concerning that note. With the use of item ordering, drag & drop, plus ItemMouseHover , the app will be just amazing and simple for all kinds of users. That's what I want integrated with your gListView control. Sir if it's still possible, please please give me your detailed code sample and/or implementation to build it, it's halfway through my thoughts and this is the only issue am facing before I start.
Thanks so so much!
|
|
|
|
|
I've used WPF Data Templates on a ListBox before and it sounds like they would work great for you. If you are not comfortable with WPF or just need to use VB.net I used a custom control that uses a FlowLayoutPanel and customizable items that works in a similar way. I think a Custom ListBox that draws its own items in the OnDrawItem event would also work. It could be strictly custom to this project or you could make custom items that create the custom template similar to what I did with the Flow Panel. I don't have a detailed example this minute, so search around for examples for now. If I have time later I may work on an example.
SSDiver2112
|
|
|
|
|
WPF would be okay yes, but as for now it may not really be the path I want to settle down for. There's more to WinForms than meets the tutorials, but thanks for the suggestion viewpoint...
The FlowLayoutPanel is a very positive build-style to go for I agree, but then managing multiple custom items at runtime and looping through the un-indexed control items may at times not be a worthwhile situation. I'll have to try and play a bit with your gListView control though to see what I can come up with in the meantime as I wait upon your example sometime later on. I'll be really grateful for that...
Glad for your support sir,
Thanks again.
|
|
|
|
|
I created the gListFlowView so I could reproduce what I was doing in WPF for an existing WinForms project. I also needed to be able to have textboxes and other controls on each item. and yes it was a chore to wire everything up.
Wish I had time to do a full article on these, but I can't right now. (maybe someday)
Here is a custom ListBox and some example templates including one like you suggested.
Create these Classes, Compile, drop three gListBoxes and three regular textboxes on a new form, and add the form code below. Set all the gListBox's DrawMode to OwnerDrawFixed and set gListbox2's itemHeight to 50 and gListBox3's itemHeight to 60.
Public Class gListBox
Inherits ListBox
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
MyBase.OnDrawItem(e)
e.DrawBackground()
Dim rect As Rectangle = New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height)
If DesignMode Then
e.Graphics.DrawRectangle(Pens.Green, rect)
TextRenderer.DrawText(DirectCast(e.Graphics, IDeviceContext), "gListBoxItem",
e.Font, e.Bounds, e.ForeColor, e.BackColor, TextFormatFlags.VerticalCenter)
Else
If Me.Items(e.Index).GetType Is GetType(String) Then
TextRenderer.DrawText(DirectCast(e.Graphics, IDeviceContext), Me.Items(e.Index).ToString,
e.Font, e.Bounds, e.ForeColor, e.BackColor, TextFormatFlags.VerticalCenter)
ElseIf Me.Items(e.Index).GetType.BaseType Is GetType(gListBoxItem) Then
CType(Me.Items(e.Index), gListBoxItem).PaintItem(Me, e.Graphics, e)
End If
End If
End Sub
End Class
Public Class gListBoxItem
Overridable Sub PaintItem(Sender as gListBox,ByRef g As Graphics,e As DrawItemEventArgs)
End Sub
End Class
Public Class glbiCustomer
Inherits gListBoxLib.gListBoxItem
Public Property Name As String
Public Property StreetAddress As String
Public Property CityStZip As String
Public Sub New(name As String, streetAddress As String, cityStZip As String)
Me.Name = name
Me.StreetAddress = streetAddress
Me.CityStZip = cityStZip
End Sub
Public Overrides Sub PaintItem(Sender As gListBoxLib.gListBox,
ByRef g As Graphics, e As DrawItemEventArgs)
MyBase.PaintItem(Sender, g, e)
Dim pt As Point = e.Bounds.Location
pt.Offset(5, 5)
TextRenderer.DrawText(DirectCast(g, IDeviceContext),
Name, e.Font, pt, e.ForeColor, e.BackColor)
pt.Offset(0, e.Font.Height)
TextRenderer.DrawText(DirectCast(g, IDeviceContext),
StreetAddress, e.Font, pt, e.ForeColor, e.BackColor)
pt.Offset(0, e.Font.Height)
TextRenderer.DrawText(DirectCast(g, IDeviceContext),
CityStZip, e.Font, pt, e.ForeColor, e.BackColor)
Dim rect As Rectangle = New Rectangle(e.Bounds.X, e.Bounds.Y,
e.Bounds.Width - 1, e.Bounds.Height)
rect.Inflate(-1, -1)
e.Graphics.DrawRectangle(Pens.Green, rect)
End Sub
End Class
Public Class glbiTitleExample
Inherits gListBoxLib.gListBoxItem
Public Property Title As String
Public Property Line1 As String
Public Property Line2 As String
Public Sub New(title As String, line1 As String, line2 As String)
Me.Title = title
Me.Line1 = line1
Me.Line2 = line2
End Sub
Public Overrides Sub PaintItem(Sender As gListBoxLib.gListBox,
ByRef g As Graphics, e As DrawItemEventArgs)
MyBase.PaintItem(Sender, g, e)
Using pn As New Pen(Brushes.Black, 2)
pn.DashStyle = Drawing2D.DashStyle.Dash
Dim pt As Point = e.Bounds.Location
Dim tfont As New Font(e.Font.FontFamily, 12, FontStyle.Bold)
pt.Offset(5, 2)
TextRenderer.DrawText(DirectCast(g, IDeviceContext),
Title, tfont, pt, e.ForeColor, e.BackColor)
pt.Offset(0, 2 + tfont.Height)
TextRenderer.DrawText(DirectCast(g, IDeviceContext),
Line1, e.Font, pt, e.ForeColor, e.BackColor)
pt.Offset(0, 3 + e.Font.Height)
TextRenderer.DrawText(DirectCast(g, IDeviceContext),
Line2, e.Font, pt, e.ForeColor, e.BackColor)
g.DrawLine(pn, 0, e.Bounds.Bottom-2, e.Bounds.Right, e.Bounds.Bottom - 2)
End Using
End Sub
End Class
Public Class Form3
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim list1 As String() = New String() {"AAAAAA", "BBBBBB", "CCCCCC", "DDDDDD",
"EEEEEE", "FFFFFF", "GGGGGG", "HHHHHH",
"IIIIII", "JJJJJJ", "KKKKKK"}
GListBox1.Items.AddRange(list1)
Dim list2 As glbiCustomer() = New glbiCustomer() {
New glbiCustomer("Tom Smith", "123 Over There", "Here, NN 09876"),
New glbiCustomer("Joe Diver", "321 Under Way", "Deep DN 33033"),
New glbiCustomer("Bilbo Baggins", "1 UnderHill", "Shire ME 12345")
}
GListBox2.Items.AddRange(list2)
Dim list3 As glbiTitleExample() = New glbiTitleExample() {
New glbiTitleExample("first item", "some information about this item",
"additional information like address, email..."),
New glbiTitleExample("second item", "some information about this item",
"additional information like address, email..."),
New glbiTitleExample("third item", "some information about this item",
"additional information like address, email...")
}
GListBox3.Items.AddRange(list3)
End Sub
Private Sub GListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) _
Handles GListBox2.SelectedIndexChanged
If GListBox2.SelectedIndex <> -1 Then
Dim item As glbiCustomer = CType(GListBox2.SelectedItem, glbiCustomer)
TextBox1.Text = item.Name
TextBox2.Text = item.StreetAddress
TextBox3.Text = item.CityStZip
End If
End Sub
End Class
SSDiver2112
|
|
|
|
|
I’m making very good use of your ListView control. It has been very useful in my app, but I was wondering… I just ran into a scenario where I needed each ListViewItem to have child items, and there’s only one control I know that can do that, the TreeView control.
I could use another TreeView I found on the internet, but I want my app to be uniform (plus I really like the gCurser). I can’t understand your code well enough to make my own from it (it’s just a bit too far ahead of mine). So I was wondering, would you be interested in making a gTreeView? Or at the very least could you point me in the right direction so I can try to make my own?
|
|
|
|
|
Much as I would like to, I don't have much free time right now to make a new control. I don't even have time to write the articles for some other controls I made and use already.
You should be able to incorporate the gCursor into another Treeview which will help with the appearance of uniformity. I wish I had time to just code all the time, but life gets in the way sometimes. Probably healthier this way but...
Wish I could be more help right now. Good Luck,
SSDiver2112
|
|
|
|
|
I have this control by my projects. I 's very stable. THANKS!
|
|
|
|
|
|
Does not support items that Inherit ListViewItem...
Kris
|
|
|
|
|
|
Excellent project. Fully functional and extremely well crafted. Runs very smoothly like any expensive commercial control we found out there. Crongratulations!
|
|
|
|
|
Excellent project. Fully functional and extremely well crafted. Runs very smoothly like any expensive commercial control we found out there. Crongratulations!
|
|
|
|
|
|
thanks for the component...
|
|
|
|
|
Glistview has been great for me exactly what I was looking for. I have been using it for many months but a couple weeks ago I started running into a problem on just ONE client and they are getting this error message. Any help would be appreciated because I have tried about everything to find the problem.
System.ArgumentException: Win32 handle that was passed to Icon is not valid or is the wrong type.
at System.Drawing.Icon..ctor(IntPtr handle, Boolean takeOwnership)
at System.Drawing.Icon..ctor(IntPtr handle)
at System.Drawing.Icon.FromHandle(IntPtr handle)
at gCursorLib.gCursor.CreateCursor(Bitmap bmp)
at gCursorLib.gCursor.MakeCursor(Boolean addEffect)
at cpi.OBC.gListView_DragHelper(gListView glist, DragDropEffects allowedEffect)
|
|
|
|
|
Hi SSDiver2112,
Your implementation is interesting. You also included, and evidently managed into depth things, which I left to abandoned, or to user, if you wish. I really enjoy mainly your graphical skills. (I am advanced graphics developer only considering qbasic ;D). But there is few things around your control which I am not much familiar with. On the other side, there is bunch of things I could consider to extend my control with. I don't think you'd be interested in joined project, and god knows if any one of us would be able to limit himself to some position in development, even if it would be for short while, supposingly. If you would be interested in joining our listviews together, I would be happy, but maybe I would be too arogant to take a main word on project division, maybe you too, and maybe it is not good idea at all BTW I have just two technical remarks on your ctl: maybe it would be good to start showing graphical tricks when leaving parental list, and stop when returning stuff back. and it would be good to set dropitems as selected on drop. The main reason why I will be little slower with graphical part supporting and expansion is that I started with need of just accurate reorderable listview, so even drag-and-drop support is addition to it. But whatever, I would like to add some more functionality to ListViewRO, with time. But generally I like lot of stuff you shown here, so with some more generallization I will be lucky to inspire with gListView in future. Finally that's great work the cursor designer editor you prepared! Yesterday I was lucky to provide point property to property window, and evenso I was not able to provide it as pointF. That's lot of work to use meta tags properly.
I hope I didn't insult you somehow. I am known to be too detail fixed, too ambitious for precise work, but still mistaking with thoughts and people, until I see everything completely.
Best regards, Matt
|
|
|
|
|
Hi Matt,
Thanks for the reply. I am maxed out on projects right now to start anything new. I am not sure by your post if you are asking how to impliment a PointF property or if you figured it out already. If you do need a PointF property look at gTrackBar - A Custom TrackBar UserControl (VB.NET)[^] It explaines how to use a TypeConverter to add a PointF property to the control.
|
|
|
|
|
Actually I could managed in your CenterPoint helper, because I created C# semaphore control with simple option to enable pathgradiency, and that pointf structure was needed to set CenterPoint as vector deviation from real center of semaphore in percents of semaphores size. So when I saw I can't manage PointF <[-1,-1],[1,1]> I used Point, which is properly described on msdn library, with changing from float<-1,1> percentage to integer<-100,100> percentage expression. Thank you for your help, I will have to decide
|
|
|
|
|
|
Thanks a ton. It seems to be perfect...actually more than what I needed for my current project.
Keep it up.
Regards,
Mujtaba Panjwani
Tiger Softwares
Software Designer and Developer
VB.NET, C#, ASP.NET, VFP
|
|
|
|
|
Cant Drop Items when I have a gcursor assigned to gcurcurssor property
does anyone else have this problem
|
|
|
|
|
That's what I need too.
Thx
|
|
|
|
|