Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

List view data save to file and load

$
0
0
I have following codes and I know how to add data from the text box entry to the header . but my question is, how can I save these entered text in each row to .txt file or .xml file, and load those information when Form load event.

for example in listbox we are able to save each entered data of the row to .Txt file or .Xml file and can load in Form Load Event.

so I want to know is it possible to do with I given codes in ListView ?.
hope you guys can help me . Will appreciated code explanation . Thank you



Inherited ListView code as follows,



Public Class ListViewEx
    Inherits ListView

    Private imgList As New ImageList

    Public Sub New()
        Me.OwnerDraw = True

        ' The control flickers if it's not double-buffered
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

        ' Configure the columns and such
        Me.View = View.Details
        Me.BackColor = Color.White
        Me.FullRowSelect = True
        Me.Columns.Add("Image and MultiLine Text", 200)

        ' Set the imagelist to change the height of the Listview items.
        imgList.ColorDepth = ColorDepth.Depth32Bit
        imgList.ImageSize = New Size(32, 32)
        Me.SmallImageList = imgList
    End Sub

    Private Sub Me_DrawColumnHeader(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles Me.DrawColumnHeader
        e.DrawDefault = True
    End Sub

    Private Sub Me_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawListViewItemEventArgs) Handles Me.DrawItem
        e.DrawDefault = False
    End Sub

    Private Sub Me_DrawSubItem(ByVal sender As Object, ByVal e As DrawListViewSubItemEventArgs) Handles Me.DrawSubItem
        If (e.ItemState And ListViewItemStates.Selected) <> 0 Then
            e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds) 'item is highlighted
        End If

        ' Draw the image and text
        If e.ColumnIndex = 0 Then
            Dim lvw As ExtraData = DirectCast(e.Item.Tag, ExtraData)
            Dim f1 As New Font("Arial", 10, FontStyle.Bold)
            Dim f2 As New Font("Arial", 8, FontStyle.Regular)
            Dim Rectf1 As RectangleF = New Rectangle(e.Bounds.X + 35, e.Bounds.Y + 3, e.Bounds.Width - 35, f1.Height)
            Dim Rectf2 As RectangleF = New Rectangle(e.Bounds.X + 35, e.Bounds.Y + 18, e.Bounds.Width - 35, f2.Height)
            Dim sf As New StringFormat
            sf.Alignment = StringAlignment.Near
            sf.Trimming = StringTrimming.EllipsisCharacter

            e.Graphics.DrawImage(lvw.MainImage, e.Bounds.X + 1, e.Bounds.Y + 1, 32, 32)
            e.Graphics.DrawString(lvw.HeaderText, f1, Brushes.Black, Rectf1, sf)
            e.Graphics.DrawString(lvw.MinorText, f2, Brushes.Black, Rectf2, sf)
        Else
            e.DrawDefault = True
        End If

    End Sub

    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'ListViewEx
        '
        Me.ResumeLayout(False)

    End Sub

    
End Class




ExtraData Class Codes as follows

Public Class ExtraData

    Public Property MainImage As Bitmap
    Public Property HeaderText As String
    Public Property MinorText As String
End Class




this codes for the button click

 Dim bm As New Bitmap("D:\sun.jpg")

        Dim lvwExtra As New ExtraData
        lvwExtra.HeaderText = TextBox1.Text
        lvwExtra.MinorText = "Minor Text"
        lvwExtra.MainImage = bm

        Dim lvw As ListViewItem = Me.ListViewEx1.Items.Add("")
        lvw.Tag = lvwExtra
    End Sub


http://imageshack.us/f/163/listview.jpg/

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>