Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Source-VB.NET] Native ListView Component

As some of you have noticed, the ListView component in .NET doesn't act exactly like the one in Windows itself as far as visually. It's pretty close, but not spot on by default. The same "problem" arises in other components as well (ie: TreeView). This class shows how to use the native theme in a ListView. I know it's not much but figured maybe someone was as tired of the shitty selecteditem(s) look in ListViews as I was. lol. Anyhow, I provided a GIF of what i'm talking about so you can see the differences in the ListViews.

Screen shot:
[Image: n5ZmH.gif]

Source Code:
Code
Namespace Components
    Public Class ListView
        Inherits System.Windows.Forms.ListView

        <Runtime.InteropServices.DllImport("uxtheme.dll", CharSet:=Runtime.InteropServices.CharSet.Unicode)> _
        Private Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Integer
        End Function

        Protected Overrides Sub CreateHandle()
            MyBase.CreateHandle()
            SetWindowTheme(Me.Handle, "explorer", Nothing)
        End Sub

        Public Sub New()
            Me.DoubleBuffered = True
            Me.View = Windows.Forms.View.Details
            Me.FullRowSelect = True
            Me.GridLines = True
        End Sub
    End Class
End Namespace
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
Looks nice, but the only difference I see is the UXTheme. Maybe I'm missing something?
(Sep 19, 2011 03:25 AM)Cody8295 Wrote:  Looks nice, but the only difference I see is the UXTheme. Maybe I'm missing something?

That is the only difference. It's not ownerdrawn or anything like that... it just makes the LV appear as it does in Windows instead of how it appears in the .NET IDE. Like I said nothing big. Certainly nothing special. haha.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
I haven't looked into listview yet. Well only a little bit and this looks like a great way to learn/start. Thank-you. And also like what you have done with selecting. Brilliant post keep em coming ;)
Hmmm..Nathan has already posted this. his thread was called Aero Listview....
(Sep 19, 2011 03:26 AM)idb. Wrote:  That is the only difference. It's not ownerdrawn or anything like that... it just makes the LV appear as it does in Windows instead of how it appears in the .NET IDE. Like I said nothing big. Certainly nothing special. haha.

Double Buffered I hope? I really hope.
(Sep 19, 2011 03:26 AM)Penthos Wrote:  I haven't looked into listview yet. Well only a little bit and this looks like a great way to learn/start. Thank-you. And also like what you have done with selecting. Brilliant post keep em coming ;)

It really isn't much man. Just a class that inherits the ListView and makes it so the hover/selection look as they do in Windows. I just didn't like the default hover/selection and did some looking into how to make it look like Windows does. It probably looks REALLY nice with grouping to be honest.

(Sep 19, 2011 03:26 AM)KingCobraXD Wrote:  Hmmm..Nathan has already posted this. his thread was called Aero Listview....

Did he? I don't recall seeing the post. If he did then I will take this down. No big deal.

(Sep 19, 2011 03:26 AM)Cody8295 Wrote:  Double Buffered I hope? I really hope.

Of course :) It also enables gridlines, enables fullrow select, and sets the default view to 'Details' instead of 'Large Icon' as well. I hate having to do that shit. haha.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
(Sep 19, 2011 03:28 AM)idb. Wrote:  Did he? I don't recall seeing the post. If he did then I will take this down. No big deal.

Of course :) It also sets the default view to 'Details' instead of 'Large Icon' as well. I hate having to do that shit. haha.

Sounds like it could shave a few seconds off development.
(Sep 19, 2011 03:29 AM)Cody8295 Wrote:  Sounds like it could shave a few seconds off development.

Which is ALWAYS the goal. haha. I think you quoted me after I edited my post though. It also enables fullrow select and gridlines.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
I am really love this member every tools . Most like his http coding
(Sep 19, 2011 03:28 AM)idb. Wrote:  Did he? I don't recall seeing the post. If he did then I will take this down. No big deal.

yeah..
https://hackforums.net/showthread.php?tid=1486126

same thing, i just didnt make all the overrides, and the layout of the code is just a bit different.

i also showed someone in a thread a week or so ago that they could do it with a treeview, and i have also seen it done with the combobox.

anyway....

i dont see any reason why you should remove your thread. Keep on keepin on.
(Sep 19, 2011 04:52 AM)nathan72389 Wrote:  yeah..
https://hackforums.net/showthread.php?tid=1486126

same thing, i just didnt make all the overrides, and the layout of the code is just a bit different.

i also showed someone in a thread a week or so ago that they could do it with a treeview, and i have also seen it done with the combobox.

anyway....

i dont see any reason why you should remove your thread. Keep on keepin on.

Ahh... my fault man. It's hard to keep up with all the threads especially when most of the ones of quality get pushed off the front right away. I also rarely read beyond the opening post these days. But yeah... this can DEF be done with the TreeView and ComboBox. More than likely can be done with every component to be completely honest.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
this might sound really stupid, but i'm still transitioning from vb6 to .net, how do you actually use this? i've created the Class and imported it into my main form, but when i drag a new listview onto it and debug it, it isn't explorer style.
That looks just much cooler. Good Job and thank you! 👍
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
Looks much cleaner. You can do this with a menustrip/contextmenustrip/TreeView to, right? Goodjob btw

[Image: HJdK32K_x]
lensert.com is the new screenshot utility, try it out now!
OSX & WINDOWS



Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by gigajewMay 24, 2021 01:43 PM 19 1,342 May 24, 2021 01:43 PM
Last Post: tux1
[C#] by huginMar 23, 2021 05:47 PM 8 393 Mar 23, 2021 05:47 PM
Last Post: hazbot77
[C#] by hugokopfJun 10, 2020 06:47 AM 4 216 Jun 10, 2020 06:47 AM
Last Post: xHeaven