M
Mamatha
Hi
I have one application ,that diplays data from database
into the listview control.While adding data to the
listview i want to display an icon to the leftside of the
first column's data.Here is my code, but icon is not
apperead with that code.
Source code
---------------
Private Sub Button7_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button7.Click
InitializeListView()
LoadList()
End Sub
Public Sub InitializeListView()
ListView1.View = View.Details
ListView1.LabelEdit = True
' Allow the user to rearrange columns.
ListView1.AllowColumnReorder = True
' Select the item and subitems when selection is
made.
ListView1.FullRowSelect = True
' Display grid lines.
ListView1.GridLines = False
' Sort the items in the list in ascending order.
ListView1.Sorting = SortOrder.Ascending
' Attach Subitems to the ListView
ListView1.Columns.Add("WebpageURL", 200,
HorizontalAlignment.Left)
ListView1.Columns.Add("Links", 70,
HorizontalAlignment.Left)
ListView1.Columns.Add("Emails", 70,
HorizontalAlignment.Left)
ListView1.Columns.Add("Comments", 100,
HorizontalAlignment.Left)
'ListView1.Columns.Add(" ", ,
HorizontalAlignment.Left)
' imageListSmall.Images.Add(Bitmap.FromFile
("C:\MySmallImage2.bmp"))
' Add the list items to the ListView
' The ListViewItemSorter property allows you to
specify the
' object that performs the sorting of items in the
ListView.
' You can use the ListViewItemSorter property in
combination
' with the Sort method to perform custom sorting.
'_lvwItemComparer = new ListViewItemComparer()
'Dim _lvwItemComparer As New
ListViewItemConverter ' ListViewItemComparer
'Me.ListView1.ListViewItemSorter = _lvwItemComparer
End Sub
Public Sub LoadList()
Dim str As String
Dim i As Integer
Dim b(100) As String
Dim strimg As String
str = Application.StartupPath & "\Email.mdb"
con.ConnectionString
= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" & str
& "' ;Persist Security Info=False"
con.Open()
cmd.Connection = con
cmd.CommandText = "select * from URL"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "URL")
' Get the table from the data set
Dim dtable As DataTable = ds.Tables("URL")
' Clear the ListView control
ListView1.Items.Clear()
' Display items in the ListView control
Dim dr As DataRow
Dim imageListSmall As New ImageList
Dim imageListLarge As New ImageList
For i = 0 To dtable.Rows.Count - 1 Step i + 1
Dim drow As DataRow = dtable.Rows(i)
' Only row that have not been deleted
If drow.RowState <> DataRowState.Deleted Then
' Define the list items
Dim lvi As ListViewItem = New ListViewItem
(drow("WebpageURL").ToString())
lvi.SubItems.Add(drow("Links").ToString())
lvi.SubItems.Add(drow("Emails").ToString())
lvi.SubItems.Add(drow("Comments").ToString
())
lvi.SubItems.Add(drow("image").ToString())
' Initialize the ImageList objects with
bitmaps.
imageListSmall.Images.Add(Bitmap.FromFile
("D:\Project-EmailExtractor\EmailExtractor20-9-04
\WindowsApplication1\bin\play.ico"))
'imageListSmall.Images.Add(Bitmap.FromFile
("C:\MySmallImage2.bmp"))
'' Add the list items to the ListView
ListView1.LargeImageList = imageListLarge
ListView1.SmallImageList = imageListSmall
ListView1.Items.Add(lvi)
' ListView1.Items(0).ImageIndex = 1
End If
Next
End Sub
I have one application ,that diplays data from database
into the listview control.While adding data to the
listview i want to display an icon to the leftside of the
first column's data.Here is my code, but icon is not
apperead with that code.
Source code
---------------
Private Sub Button7_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button7.Click
InitializeListView()
LoadList()
End Sub
Public Sub InitializeListView()
ListView1.View = View.Details
ListView1.LabelEdit = True
' Allow the user to rearrange columns.
ListView1.AllowColumnReorder = True
' Select the item and subitems when selection is
made.
ListView1.FullRowSelect = True
' Display grid lines.
ListView1.GridLines = False
' Sort the items in the list in ascending order.
ListView1.Sorting = SortOrder.Ascending
' Attach Subitems to the ListView
ListView1.Columns.Add("WebpageURL", 200,
HorizontalAlignment.Left)
ListView1.Columns.Add("Links", 70,
HorizontalAlignment.Left)
ListView1.Columns.Add("Emails", 70,
HorizontalAlignment.Left)
ListView1.Columns.Add("Comments", 100,
HorizontalAlignment.Left)
'ListView1.Columns.Add(" ", ,
HorizontalAlignment.Left)
' imageListSmall.Images.Add(Bitmap.FromFile
("C:\MySmallImage2.bmp"))
' Add the list items to the ListView
' The ListViewItemSorter property allows you to
specify the
' object that performs the sorting of items in the
ListView.
' You can use the ListViewItemSorter property in
combination
' with the Sort method to perform custom sorting.
'_lvwItemComparer = new ListViewItemComparer()
'Dim _lvwItemComparer As New
ListViewItemConverter ' ListViewItemComparer
'Me.ListView1.ListViewItemSorter = _lvwItemComparer
End Sub
Public Sub LoadList()
Dim str As String
Dim i As Integer
Dim b(100) As String
Dim strimg As String
str = Application.StartupPath & "\Email.mdb"
con.ConnectionString
= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" & str
& "' ;Persist Security Info=False"
con.Open()
cmd.Connection = con
cmd.CommandText = "select * from URL"
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "URL")
' Get the table from the data set
Dim dtable As DataTable = ds.Tables("URL")
' Clear the ListView control
ListView1.Items.Clear()
' Display items in the ListView control
Dim dr As DataRow
Dim imageListSmall As New ImageList
Dim imageListLarge As New ImageList
For i = 0 To dtable.Rows.Count - 1 Step i + 1
Dim drow As DataRow = dtable.Rows(i)
' Only row that have not been deleted
If drow.RowState <> DataRowState.Deleted Then
' Define the list items
Dim lvi As ListViewItem = New ListViewItem
(drow("WebpageURL").ToString())
lvi.SubItems.Add(drow("Links").ToString())
lvi.SubItems.Add(drow("Emails").ToString())
lvi.SubItems.Add(drow("Comments").ToString
())
lvi.SubItems.Add(drow("image").ToString())
' Initialize the ImageList objects with
bitmaps.
imageListSmall.Images.Add(Bitmap.FromFile
("D:\Project-EmailExtractor\EmailExtractor20-9-04
\WindowsApplication1\bin\play.ico"))
'imageListSmall.Images.Add(Bitmap.FromFile
("C:\MySmallImage2.bmp"))
'' Add the list items to the ListView
ListView1.LargeImageList = imageListLarge
ListView1.SmallImageList = imageListSmall
ListView1.Items.Add(lvi)
' ListView1.Items(0).ImageIndex = 1
End If
Next
End Sub