none
Sorting items like Windows Explorer

    Question

  • Hi All.

    I am working on an explorer and i wont to sort items like windows explorer, or how to change the bounds or size of items

    The pictures below shown exactly what i mean.

    This is the Windows Explorer.

    This is my Explorer in the same folder.

    I have search the internet but nothing found plz Help.

    Thursday, May 01, 2014 12:23 PM

Answers

  • HI ALL.

    I want to thanks all you to respond in this question.

    But, unfortunately, we did not find the correct answer. In this case i will close this question, marking this as an answer, and i promise, if i found the solution, i will posted here.

    Also, check back in another time.

    Greetings
    Toni

    Wednesday, May 14, 2014 11:31 AM

All replies

  • What control are you using to display these items in?

    La vida loca

    Thursday, May 01, 2014 12:38 PM
  • HI

    listview

    Thursday, May 01, 2014 12:51 PM
  • Maybe setting the Listviews view to something will do it. I'm not sure. Below are the 5 choices I believe.

    ListView1.View = View.Details
    ListView1.View = View.LargeIcon
    ListView1.View = View.List
    ListView1.View = View.SmallIcon
    ListView1.View = View.Tile


    La vida loca

    Thursday, May 01, 2014 1:52 PM
  • In the second picture the listview is in Smallicon view.
    The rest of view types i don't have any problem, only in Smallicon.

    Thursday, May 01, 2014 1:58 PM
  • I have write this routine but this works only in ListView1.View =  View.List

    You can adjust the distance as much as you want.

            Dim D As Integer
            Dim D1 As Integer
    
            For X = 0 To ListView1.Items.Count - 1
                D = D + Len(ListView1.Items(X).Text)
                If D1 < Len(ListView1.Items(X).Text) Then D1 = Len(ListView1.Items(X).Text)
            Next
            D = D / ListView1.Items.Count - 1
            D = D * ListView1.Font.Size ' Here give the average distance of all items
            D1 = D1 * ListView1.Font.Size ' Here the D1 gives the biggest width of the listed item
            
    	ListView1.Columns(0).Width = D
            '----------------------------------------------------------------------------------
    
            ListView1.View = Windows.Forms.View.List ' View.List




    Thursday, May 01, 2014 3:32 PM
  • I have write this routine but this works only in ListView1.View =  View.List

    You can adjust the distance as much as you want.

            Dim D As Integer
            Dim D1 As Integer
    
            For X = 0 To ListView1.Items.Count - 1
                D = D + Len(ListView1.Items(X).Text)
                If D1 < Len(ListView1.Items(X).Text) Then D1 = Len(ListView1.Items(X).Text)
            Next
            D = D / ListView1.Items.Count - 1
            D = D * ListView1.Font.Size ' Here give the average distance of all items
            D1 = D1 * ListView1.Font.Size ' Here the D1 gives the biggest width of the listed item
            
    	ListView1.Columns(0).Width = D
            '----------------------------------------------------------------------------------
    
            ListView1.View = Windows.Forms.View.List ' View.List




    Hi,

    In my opinion, it is due to the length of these items, it shows longer than that column.

    First, Len(ListView1.Items(X).Text) could not get the width of that text of that item, we could try the following way to get that witdth.

     Dim g As Graphics = ListView1.CreateGraphics
     Dim intWidth as integer = g.MeasureString(ListView1.Items(index).Text, ListView1.Font).Width 

    And we also need to change the text which shows too longer by replacing these last characters with "...".

    Here is a simple function, you could change it to suit your project by calling it within form_load and form_Resize events.

     Public Sub ResizeListView()
            With ListView1
                For index As Integer = 0 To ListView1.Columns.Count - 1
                    .Columns(index).Width = CInt(.Width * 0.24)
                Next
                With .Items
                    For index As Integer = 0 To .Count - 1
                        Dim g As Graphics = ListView1.CreateGraphics
                        With ListView1.Items(index)
                            For intLength As Integer = 0 To .Text.Length - 2
                                If g.MeasureString(.Text.Substring(0, intLength), ListView1.Font).Width > CInt(ListView1.Width * 0.2) Then
                                    ListView1.Items(index).Text = ListView1.Items(index).Text.Substring(0, intLength - 4) & "..."
                                    Exit For
                                End If
                            Next
                        End With
                    Next
                End With
            End With
        End Sub

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 02, 2014 7:30 AM
    Moderator
  • Hi Thanks for reply and the code.
    I can say it is better than my but in the SmallIcon view doesn't work works good in list view.
    How to make this code to work for both view List and SmallIcon.


    I apologize if I'm 2 late to respond.


    Friday, May 02, 2014 3:40 PM
  • Hi Thanks for reply and the code.
    I can say it is better than my but in the SmallIcon view doesn't work works good in list view.
    How to make this code to work for both view List and SmallIcon.


    I apologize if I'm 2 late to respond.


    Hi,

    Just feel free to let us know whenever you got any concern.

    In order to get your issue solved more efficiently, you could share your current code and the result with us.

    What I shared is just a simple sample about how to dealing with the string width and the column width.

    For my understanding, in this case with smallIcon view we need to consider the icon's width too.

    The option will be changed from

    g.MeasureString(.Text.Substring(0, intLength), ListView1.Font).Width > CInt(ListView1.Width * 0.2) 
                                    

    to the one

    g.MeasureString(.Text.Substring(0, intLength), ListView1.Font).Width + theInconWidth > CInt(ListView1.Width * 0.2) Then
                                    

    To get the incon width, you could just get the image from the imagelist by index and get its width property.

    Hope it helps.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 05, 2014 9:08 AM
    Moderator
  • Hi

    I have make a litle program just take a look.

    You need 4 textboxes 1 Button 2 Labels and a Listview

    and the code.

    Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim g As Graphics = Me.CreateGraphics() Dim D Dim REGULA REGULA = 200 D = Size.Round(g.MeasureString(TextBox1.Text, TextBox1.Font)).Width For X = 0 To Len(TextBox1.Text) If g.MeasureString(TextBox1.Text.Substring(0, X), TextBox1.Font).Width > REGULA Then TextBox2.Text = TextBox1.Text.Substring(0, X) & "..." Exit For Else TextBox2.Text = TextBox1.Text End If Next Dim R As Rectangle R.Size = New Size(REGULA + g.MeasureString("...", TextBox1.Font).Height, g.MeasureString(TextBox1.Text, TextBox1.Font).Height) R.Location = New Point(TextBox2.Left, TextBox2.Top + TextBox2.Height) g.DrawRectangle(Pens.Black, R) End Sub Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged Dim g As Graphics = Lv1.CreateGraphics() Dim D Dim REGULA Dim flags As TextFormatFlags = TextFormatFlags.NoPadding Dim startPoint As New Point(0, TextBox1.Top + TextBox1.Height) Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue) Dim size As Size = TextRenderer.MeasureText(Lv1.CreateGraphics, TextBox1.Text, TextBox1.Font, proposedSize, flags) Dim rect As Rectangle = New Rectangle(startPoint, size) Dim R As Rectangle g.Clear(Me.BackColor) REGULA = 400 D = Size.Round(g.MeasureString(TextBox1.Text, TextBox1.Font)).Width For X = 0 To Len(TextBox1.Text) TextBox3.Text = Size.Round(g.MeasureString(TextBox1.Text.Substring(0, X), TextBox1.Font)).Width ' g.MeasureString(TextBox1.Text.Substring(0, X), TextBox1.Font).Width If g.MeasureString(TextBox1.Text.Substring(0, X), TextBox1.Font).Width > REGULA Then TextBox2.Text = TextBox1.Text.Substring(0, X - 1) & "..." Exit For Else TextBox2.Text = TextBox1.Text End If Next TextRenderer.DrawText(Lv1.CreateGraphics, TextBox2.Text, TextBox1.Font, startPoint, Color.Black, flags) 'R.Size = New Size(g.MeasureString(TextBox2.Text, TextBox1.Font).Height, g.MeasureString(TextBox2.Text, TextBox1.Font).Height) R.Size = TextRenderer.MeasureText(Lv1.CreateGraphics, TextBox2.Text, TextBox1.Font, proposedSize, flags) R.Location = rect.Location ' New Point(startPoint.X, 10) g.DrawRectangle(Pens.Black, R) TextBox4.Text = Len(TextBox2.Text) Exit Sub R.Size = New Size(REGULA + g.MeasureString("...", TextBox1.Font).Height, g.MeasureString(TextBox1.Text, TextBox1.Font).Height) R.Location = New Point(TextBox2.Left, TextBox2.Top - TextBox2.Height) g.DrawRectangle(Pens.Black, R) Dim stringSize As New SizeF stringSize = g.MeasureString(TextBox2.Text, TextBox1.Font) g.DrawRectangle(New Pen(Color.Red, 1), 0, TextBox1.Top + TextBox1.Height, stringSize.Width, stringSize.Height) g.DrawString(TextBox2.Text, TextBox1.Font, Brushes.Black, New PointF(0, TextBox1.Top + TextBox1.Height)) End Sub Private Sub MeasureStringMin(ByVal e As PaintEventArgs) ' Set up string. Dim measureString As String = "Measure String" Dim stringFont As New Font("Arial", 16) ' Measure string. Dim stringSize As New SizeF stringSize = e.Graphics.MeasureString(measureString, stringFont) ' Draw rectangle representing size of string. e.Graphics.DrawRectangle(New Pen(Color.Red, 1), 0.0F, 0.0F, _ stringSize.Width, stringSize.Height) ' Draw string to screen. e.Graphics.DrawString(measureString, stringFont, Brushes.Black, _ New PointF(0, 0)) End Sub Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint DrawALineOfText(e) End Sub Private Sub DrawALineOfText(ByVal e As PaintEventArgs) Dim g As Graphics = Me.CreateGraphics() ' Declare strings to render on the form. Dim stringsToPaint() As String = {"Tail", "Spin", " Toys"} ' Declare fonts for rendering the strings. Dim fonts() As Font = {New Font("Arial", 14, FontStyle.Regular), _ New Font("Arial", 14, FontStyle.Italic), _ New Font("Arial", 14, FontStyle.Regular)} Dim startPoint As New Point(10, 10) ' Set TextFormatFlags to no padding so strings are drawn together. Dim flags As TextFormatFlags = TextFormatFlags.NoPadding ' Declare a proposed size with dimensions set to the maximum integer value. Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue) ' Measure each string with its font and NoPadding value and draw it to the form. For i As Integer = 0 To stringsToPaint.Length - 1 Dim size As Size = TextRenderer.MeasureText(e.Graphics, stringsToPaint(i), fonts(i), proposedSize, flags) Dim rect As Rectangle = New Rectangle(startPoint, size) TextRenderer.DrawText(e.Graphics, stringsToPaint(i), fonts(i), startPoint, Color.Black, flags) Dim R As Rectangle R.Size = New Size(g.MeasureString(stringsToPaint(i), fonts(i)).Height, g.MeasureString(stringsToPaint(i), fonts(i)).Height) R.Location = New Point(startPoint.X, 10) e.Graphics.DrawRectangle(Pens.Black, rect) startPoint.X += size.Width Next End Sub End Class

    The value of the variable REGULA it can be the Lv1.Columns(0).Width.


    Just type in Textbox1.

    Greetings

    Toni

     


    Tuesday, May 06, 2014 6:02 PM
  • Hi,

    You could share the sample with us by uploading it to OneDrive and sharing its link here. :)

    But I am confused that whether this sample has anything with your original issue, is this your current code to solve that issue?

    Based on your previous reply, it should have some icons within SmallIcon view, right?

    The result of your sample I tested shows as the following image, you will find that text in that listview will disappear when I minimize the form.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 08, 2014 3:16 AM
    Moderator
  • Hi

    I think you have right we are out of course.
    If you don't have any propose then i will close the question.
    In this link is the update from the text length code.
    http://1drv.ms/1qhxOID
    and the picture as a gift.

    It will be nice of you to share with me your OneDrive share folder ;-)

    How do you make my text from previous reply grey.
    I will like to do it also for my replies.

    Thursday, May 08, 2014 10:59 AM
  • Hi

    I think you have right we are out of course.
    If you don't have any propose then i will close the question.
    In this link is the update from the text length code.
    http://1drv.ms/1qhxOID
    and the picture as a gift.

    It will be nice of you to share with me your OneDrive share folder ;-)

    How do you make my text from previous reply grey.
    I will like to do it also for my replies.

    You press the quote button if that's what you mean. Which of course let's everybody know which post you are replying too.

    Also I just found this information

    "Displaying the Folder View

    Once you have created the child window and returned it to Windows Explorer, you can display the folder's contents. Typically, extensions display their information by having the child window host either a list view control or a WebBrowser control. The list view control allows you to replicate the Windows Explorer classic view. The WebBrowser control allows you to use a Dynamic HTML (DHTML) document to display your information, much like the Windows Explorer Web view. For further information, refer to the documentation of those controls."

    From this link - Implementing a Folder View - which has to do with Legacy Shell or something.

    Here's an image from a 4x4 excursion. I didn't get close to the edge when taking the video due to the 4000 ft or so drop off.


    La vida loca




    Thursday, May 08, 2014 11:39 AM
  • Also I just found this information

    "Displaying the Folder View

    Once you have created the child window and returned it to Windows Explorer, you can display the folder's contents. Typically, extensions display their information by having the child window host either a list view control or a WebBrowser control. The list view control allows you to replicate the Windows Explorer classic view. The WebBrowser control allows you to use a Dynamic HTML (DHTML) document to display your information, much like the Windows Explorer Web view. For further information, refer to the documentation of those controls."

    From this link - Implementing a Folder View - which has to do with Legacy Shell or something.

    Here's an image from a 4x4 excursion. I didn't get close to the edge when taking the video due to the 4000 ft or so drop off.



    What do you mean ?.


    Thursday, May 08, 2014 12:43 PM
  • I mean it's possible you could research that information and find out how the Windows Explorer view of folders or whatever could be recreated like you want in your app which apparently you are having a difficult time performing using the listview control as it is right now without some sort of modification. Or maybe you could use a WebBrowser control somehow. Or maybe a combination of a ListView and WebBrowser or TreeView and WebBrowser.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            WebBrowser1.Navigate("C:\Users\John\Desktop")
        End Sub
    
    End Class

    First image is after navigation to desktop. Second image is after clicking on folder "Alarms - Whoop".

    Image of Form maximized and Desktop navigated to.


    La vida loca





    Thursday, May 08, 2014 2:56 PM
  • For answering this question the following work must be done.

    1) Measure the text of item with, the width from icon.
    2) Set the first column to the lenght of the value you found, or the length you wont.
    3) Cut the item text in this length (Example is below)

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            lv1.View = System.Windows.Forms.View.SmallIcon
            LVICutText()
            lv1.Sort()
    
        End Sub
    
    
        Private Sub LVICutText()
            Dim g As Graphics = lv1.CreateGraphics()
            Dim D, D1, REGULA
            REGULA = 200
            'D = 0
            'D1 = 0
            'For index As Integer = 0 To lv1.Columns.Count - 1
            lv1.Columns(0).Width = REGULA
            'Next
            REGULA = lv1.Columns(0).Width - g.MeasureString("WW", lv1.Font).Width ' "WW" because the Width is bigger than "..."
            'lv1.Columns(0).Width = rect.Width
            For X = 0 To lv1.Items.Count - 1
    
                Dim flags As TextFormatFlags = TextFormatFlags.NoPadding
                Dim startPoint As New System.Drawing.Point(0, 0)
                Dim proposedSize As Size = New Size(Integer.MaxValue, Integer.MaxValue)
                For X1 = 0 To Len(lv1.Items(X).Text)
                    If g.MeasureString(lv1.Items(X).Text.Substring(0, X1), lv1.Font).Width > REGULA Then
                        lv1.Items(X).Text = lv1.Items(X).Text.Substring(0, X1 - 1) & "..."
                        Dim size As Size = TextRenderer.MeasureText(lv1.CreateGraphics, lv1.Items(X).Text, lv1.Font, proposedSize, flags)
                        Dim rect As Rectangle = New Rectangle(startPoint, size)
                        If lv1.Columns(0).Width < rect.Width Then
                            lv1.Columns(0).Width = rect.Width
                        End If
                        Exit For
                    End If
                Next
                'D = D + TextRenderer.MeasureText(lv1.CreateGraphics, lv1.Items(X).Text, lv1.Font, proposedSize, flags)
            Next
        End Sub
    
    
    

    4) Set listview to View.smallIcon, sort them again.

    You will have the sorting like windows but the rename of the item will be a problem because we have change it.
    If you wont to edit the item label (the same as explorer das for rename the files.)
    You must give the original name back to the items label.
    Below i have take some pictures to make it easy to understand.


    1) Pictures from Win explorer.

    2) Pictures from my explorer.

    You can see if you click for rename the text on label is not the original name but the blue rectangle of

    listview is the length of the original item.Name.

    Until now i don't have find the solution.

    I hope that was helpful to make you understand.

    Any help will be appreciated.

    Greetings

    Toni

    Thursday, May 08, 2014 5:55 PM
  • Hi,

    Mr. Monkeyboy has shared a simple way to get that done.

    If you want to keep on finding the way to solve the issue of your control, then I would suggest you consider using the following way to handle the rename issue.

    >>You will have the sorting like windows but the rename of the item will be a problem because we have change it.
    If you wont to edit the item label (the same as explorer das for rename the files.)
    You must give the original name back to the items label.<<

    Then how about adding a dataset to store all texts of these items? We could set each text with dealing with the value form that dataset instead of from the one dealing with the item's text.

    Change the following line

     lv1.Items(X).Text = lv1.Items(X).Text.Substring(0, X1 - 1) & "..."

    to

    lv1.Items(X).Text = ds.Tables(0).Rows(index)(0).ToString().Substring(0, X1 - 1) & "..."

    Hope it helps.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, May 09, 2014 5:55 AM
    Moderator
  • Then how about adding a dataset to store all texts of these items? We could set each text with dealing with the value form that dataset instead of from the one dealing with the item's text.

    I have already store my problem is in the time from rename i can't insert into label any text or get any

    text from label for example

    ByVal e As System.Windows.Forms.LabelEditEventArgs

    e.Label is read only and has no value in ( Private Sub listview1_BeforeLabelEdit .....)

    the listview1.item(xx).text is the value of e.label

    the listview1.item(xx).name has the original file name

    i can't find the way to insert the listview1.item(xx).name into

    e.label

    Greetings

    Toni

    Friday, May 09, 2014 6:33 AM
  • Then how about adding a dataset to store all texts of these items? We could set each text with dealing with the value form that dataset instead of from the one dealing with the item's text.

    I have already store my problem is in the time from rename i can't insert into label any text or get any

    text from label for example

    ByVal e As System.Windows.Forms.LabelEditEventArgs

    e.Label is read only and has no value in ( Private Sub listview1_BeforeLabelEdit .....)

    the listview1.item(xx).text is the value of e.label

    the listview1.item(xx).name has the original file name

    i can't find the way to insert the listview1.item(xx).name into

    e.label

    Greetings

    Toni


    Without your code we could not got any idea how to solve that, mind sharing?

    remember make the reply as answer and vote the reply as helpful if it helps.

    Friday, May 09, 2014 6:40 AM
  • Without your code we could not got any idea how to solve that, mind sharing?

    If you look above there is plenty of code and pictures to make you understand

    where the problem is.

    If you mean the hole code .... NO.

    1) Is to big for this forum.

    2) Lot of work in it to post it.

    I hope you understand.

    Greetings

    Toni

    Friday, May 09, 2014 6:58 AM
  • Then how about adding a dataset to store all texts of these items? We could set each text with dealing with the value form that dataset instead of from the one dealing with the item's text.

    I have already store my problem is in the time from rename i can't insert into label any text or get any

    text from label for example

    ByVal e As System.Windows.Forms.LabelEditEventArgs

    e.Label is read only and has no value in ( Private Sub listview1_BeforeLabelEdit .....)

    the listview1.item(xx).text is the value of e.label

    the listview1.item(xx).name has the original file name

    i can't find the way to insert the listview1.item(xx).name into

    e.label

    Greetings

    Toni

    Well it seems to me that unless your code is proprietary somehow that you should just upload your project in a zip file to your onedrive account and provide a link to that in this thread in a post so that others can download the project, bring it up in Visual Studio, attempt to fix the issue and quit messing around with all of these posts for no reason in order to correct the issue once and for all.

    Because, IMO (In My Opinion), nothing is being resolved using this method of conversation.


    La vida loca

    Friday, May 09, 2014 7:00 AM
  • Well it seems to me that unless your code is proprietary somehow that you should just upload your project in a zip file to your onedrive account and provide a link to that in this thread in a post so that others can download the project, bring it up in Visual Studio, attempt to fix the issue and quit messing around with all of these posts for no reason in order to correct the issue once and for all.



    Greetings

    Toni

    Friday, May 09, 2014 7:25 AM
  • Well it seems to me that unless your code is proprietary somehow that you should just upload your project in a zip file to your onedrive account and provide a link to that in this thread in a post so that others can download the project, bring it up in Visual Studio, attempt to fix the issue and quit messing around with all of these posts for no reason in order to correct the issue once and for all.



    Greetings

    Toni

    Well I'm not sure what that means but if it means piss off then so be it. Although if you did what I mentioned I've no doubt your issue would be resolved fairly quickly. After all your known for requesting code according to your requirement which leads me to believe you are not necessarily capable of doing what you want to do. Even via research which you don't appear very capable of.


    La vida loca


    Friday, May 09, 2014 7:27 AM
  • Well I'm not sure what that means but if it means piss off then so be it. Although if you did what I mentioned I've no doubt your issue would be resolved fairly quickly. After all your known for requesting code according to your requirement which leads me to believe you are not necessarily capable of doing what you want to do. Even via research which you don't appear very capable of.



    I don't mean nothing.

    I Have to go work, i will make a code and i will posted here later.

    Greetings

    Toni

    Friday, May 09, 2014 8:13 AM
  • Then how about adding a dataset to store all texts of these items? We could set each text with dealing with the value form that dataset instead of from the one dealing with the item's text.

    I have already store my problem is in the time from rename i can't insert into label any text or get any

    text from label for example

    ByVal e As System.Windows.Forms.LabelEditEventArgs

    e.Label is read only and has no value in ( Private Sub listview1_BeforeLabelEdit .....)

    the listview1.item(xx).text is the value of e.label

    the listview1.item(xx).name has the original file name

    i can't find the way to insert the listview1.item(xx).name into

    e.label

    Greetings

    Toni

    Hi,

    I agree with Risa and MonkeyBoy that it is quite hard to get what caused this issue and how to solve that, for example, if you share how did you edit that item with what event and how did you deal with the event afterlabeledit will help a lot.

    After a while trying to test what you mean, then I would suggest you have a look at the following suggestion.

    Before you call the BeginEdit method of that item, set its Text to its Name, and the second event to store the e.label before you set its CancelEdit  to true, and then reset its text again.

     Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListView1.MouseDoubleClick
            ListView1.SelectedItems(0).Text = ListView1.SelectedItems(0).Name
            ListView1.SelectedItems(0).BeginEdit()
        End Sub
    
        Private Sub ListView1_AfterLabelEdit(sender As Object, e As LabelEditEventArgs) Handles ListView1.AfterLabelEdit
            Dim g As Graphics = ListView1.CreateGraphics
            Dim index As Integer = e.Item
            With ListView1.Items(index)
                ListView1.Items(index).Name = e.Label
                ListView1.Items(index).Text = e.Label
                e.CancelEdit = True
                For intLength As Integer = 0 To .Text.Length - 2
                    If g.MeasureString(.Text.Substring(0, intLength), ListView1.Font).Width > CInt(ListView1.Width * 0.2) Then
                        ListView1.Items(index).Text = ListView1.Items(index).Text.Substring(0, intLength - 4) & "..."
                        Exit For
                    End If
                Next
    
            End With
        End Sub

    Result:

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 09, 2014 8:17 AM
    Moderator
  • Hi all

    In my OneDrive you can download the explorer as i promised in this link.

    Sorry no more available.

    Play with SmallIcon view and you will see where the problem is.

    Greetings

    Toni.


    Friday, May 09, 2014 2:45 PM
  • Hi,

    Have you tried my previous suggestion? That should be able to solve your rename issue.

    Based on the code of that project you shared, I didn't found anything using the similar way I suggested.

    So I am afraid that We are trying to help you with just a simple sample, but you need to code it by yourself with the similar way.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 12, 2014 8:50 AM
    Moderator
  • Hi,

    Have you tried my previous suggestion? That should be able to solve your rename issue.

    Based on the code of that project you shared, I didn't found anything using the similar way I suggested.

    So I am afraid that We are trying to help you with just a simple sample, but you need to code it by yourself with the similar way.

    Regards.


    Hi
    Sorry for 2 late response , Yesterday i was to my mother to celebrate the mother day.
    I have try of course your routine don't helps 2 much.

    Greetings

    Toni

    Tuesday, May 13, 2014 2:32 AM
  • Hi,

    Have you tried my previous suggestion? That should be able to solve your rename issue.

    Based on the code of that project you shared, I didn't found anything using the similar way I suggested.

    So I am afraid that We are trying to help you with just a simple sample, but you need to code it by yourself with the similar way.

    Regards.


    Hi
    Sorry for 2 late response , Yesterday i was to my mother to celebrate the mother day.
    I have try of course your routine don't helps 2 much.

    Greetings

    Toni

    Hi,

    Would you mind sharing how did you code with the way I suggested with us in that sample you shared?

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 13, 2014 5:35 AM
    Moderator
  • I think I found a way to make this work. However I did not add ICONs to my ListView like your project, which I downloaded and ran the example executable, does. But I believe I have a possible solution when using ICONs too.

    Anyhow this is the before and after image using "ListView1.View = View.SmallIcon". Note how everything lines up in the second image like it does in Windows Explorer but not in the first image.

    The code I used is below.

    After loading the ListView with Items I used code to get the width of each string in the ListViews Items.

    An integer was then set to the amount of the widest string in the ListViews Items.

    I don't know why this works but after all that I then add a Column to the ListView. The Column does not display at all. It's Width is set to the integers value + 5. For some reason this makes the alignment work.

    I just set "ListView1.Columns.Add("", LView1ColWidth - 10, HorizontalAlignment.Center)" when adding the Column and that makes the widest text just about touch the text to the right of it.

    Although because I don't have any ICONs in the ListViews Items you need to make up for that width I believe. I suppose you could get an ICONs width from however you get the ICON to display it in the ListView.

    Or perhaps this "Dim LV1IndentCount As Integer = ListView1.Items.Item(i).IndentCount" in the For/Next statment could be added to the integer that has the width of the widest text in the ListViews items. See the image below for IndentCount.

    Or maybe get the image index's image width or something. I don't know.

    Option Strict On
    
    Public Class Form1
    
        Dim g As Graphics = Me.CreateGraphics
    
        Dim LView1StringSize As System.Drawing.SizeF
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            ListView1.View = View.SmallIcon
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ListView1.Items.Clear()
            ListView1.Columns.Clear()
            Dim FBD As New FolderBrowserDialog
            FBD.Description = "Add Folders and Files to ListView"
            FBD.SelectedPath = "C:\Users\John\Desktop"
            Dim FolderInfoSplit() As String
            If FBD.ShowDialog = Windows.Forms.DialogResult.OK Then
                For Each FolderInfo In My.Computer.FileSystem.GetDirectories(FBD.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly)
                    FolderInfoSplit = FolderInfo.Split("\"c)
                    ListView1.Items.Add(FolderInfoSplit(FolderInfoSplit.Count - 1))
                    
                Next
            End If
    
            Dim LView1ColWidth As Integer = 0
    
            For i = 0 To ListView1.Items.Count - 1
                LView1StringSize = g.MeasureString(ListView1.Items.Item(i).Text, ListView1.Font)
                If LView1StringSize.Width > CSng(LView1ColWidth) Then LView1ColWidth = CInt(LView1StringSize.Width)
            Next
    
            ListView1.Columns.Add("Hello", LView1ColWidth + 5, HorizontalAlignment.Center)
    
        End Sub
    
    End Class


    La vida loca





    Tuesday, May 13, 2014 2:39 PM
  • HI ALL.

    I want to thanks all you to respond in this question.

    But, unfortunately, we did not find the correct answer. In this case i will close this question, marking this as an answer, and i promise, if i found the solution, i will posted here.

    Also, check back in another time.

    Greetings
    Toni

    Wednesday, May 14, 2014 11:31 AM
  • But, unfortunately, we did not find the correct answer.

    Well it's your thread so I suppose if nothing answered your question then that's that. Although with a bit more work to the code I provide and adding Penguin Icons to represent Folders and Skull Icons to represent files I got this going. To me it looks just like the window in Windows Explorer. Except I didn't get the distance between the columns correct yet. But I did terminate strings over a certain count with three periods "..." like windows explorer does. I even provided a NumericUpDown to allow the string count to be changed in the view for SmallIcons.

    And even though the Icons I added to ImageList1 are 128 x 128 pixels when they are in ImageList1 it shows their width and height as 16 pixels. So it was relatively easy to create the column with an appropriate width.

    But since the code I provided has no use then c'est la vie.

    Windows Explorer view of some of the files


    La vida loca


    Wednesday, May 14, 2014 4:42 PM