如何将图像添加到listviewbox? [英] How do I add an image to the listviewbox?

查看:96
本文介绍了如何将图像添加到listviewbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我已经编写了一些代码来从我的SQL服务器中提取信息并且它工作非常好,但是我没有任何想法它可以在SQL中填充实际图像。



 UserListView.View = View.Details 
UserListView.GridLines = True
Dim strQ As 字符串 = 字符串 .Empty
strQ =( SELECT tblUser.UserPicture AS'Picture',tblUser.EmployeeNum AS'Employee#',tblUser.UserLastName AS'Lose Name',tblUser.UserFirstName AS'First Name',tblUser .UserEmail AS'Email',tblUser.UserInactive AS'Inactive'FROM tblUser INNER JOIN tblUserTerminals ON tblUser.XID = tblUserTerminals.UserXID WHERE tblUserTerminals.TerminalXID ='& ValueTextBox.Text &安培; 'AND tblUser.EmployeeNum<>'0'ORDER BY tblUser.UserLastName,tblUser.UserFirstName ASC
command = SqlCommand(strQ,con2)
DA = SqlDataAdapter(命令)
DS = DataSet
DA.Fill(DS,
Dim i As 整数 = 0
昏暗 j 作为 整数 = 0
' 将列添加到UserListView
对于 i = < span class =code-digit> 0 DS.Tables( 0 )。 Columns.Count - 1
UserListView.Columns.Add(DS.Tables( 0 )。列(i).ColumnName.ToString())
下一步
' < span class =code-comment>将项添加到UserListView
对于 i = 0 DS.Tables( 0 )。Rows.Count - 1
对于 j = 0 DS.Tables( 0 )。Columns.Count - 1
ItemColl(j)= DS.Tables( 0 )。行(i)(j).ToString()
下一步
Dim lvi 作为 ListViewItem(ItemColl)
UserListView.Items.Add(lvi)
Dim lviimage 作为 ListViewItem(ItemColl)

下一页







任何帮助将不胜感激!



谢谢!

解决方案

这个问题的主要部分被问了很多次,回答它会很糟糕再次。请参阅: http://www.codeproject.com/search.aspx?q=database+store+%28bitmaps+OR+images+ OR +图片%29 +%28%22ADO.NET%22 + OR +%22C%23%22 + OR +%22VB.NET%22%29& doctypeid = 1%3b5 [ ^ ]。



很多例如,对于网站/应用程序,只存储图像名称并将图像本身存储在服务器端的文件系统中会更实用。



剩下的问题是在 ListView 中显示图像。但问题是:你没有确切地说明你的意思。使用此名称作为简单类型名称有不同的不相关(但相似)类型,那么哪一个?我不想做任何猜测。始终指定完整类型名称。更好的是,只需阅读此类型的文档。







至于呈现图像 System.Windows.Forms.ListView 的实例,你可以在这篇MSDN文章中得到这个想法:

https://msdn.microsoft.com/en-us/library/ system.windows.forms.listview.smallimagelist%28v = vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/ system.windows.forms.listview.largeimagelist%28v = vs.110%29.aspx [ ^ ]。



这里的主要内容是:你必须在一个类型的对象中收集所有图像System.Windows.Forms.ImageList ListView 的属性。然后列表视图中显示的图像将由分配给该项目的属性 ImageIndex 的索引定义。



列表视图的显示取决于 View 属性的值:

https://msdn.microsoft.com/en-us/library/system.windows.forms .listview.view%28v = vs.110%29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.forms.view %28v = vs.110%29.aspx [ ^ ]。



-SA

Hello,

I've written some code to pull information from my SQL server and it is working marvelously, however I don't have the slightest idea how it can populate the actual image within SQL.

UserListView.View = View.Details
        UserListView.GridLines = True
        Dim strQ As String = String.Empty
        strQ = ("SELECT tblUser.UserPicture AS 'Picture', tblUser.EmployeeNum AS 'Employee#', tblUser.UserLastName AS 'Last Name', tblUser.UserFirstName AS 'First Name', tblUser.UserEmail AS 'Email', tblUser.UserInactive AS 'Inactive' FROM tblUser INNER JOIN tblUserTerminals ON tblUser.XID=tblUserTerminals.UserXID WHERE tblUserTerminals.TerminalXID = '" & ValueTextBox.Text & "' AND tblUser.EmployeeNum <> '0' ORDER BY tblUser.UserLastName, tblUser.UserFirstName ASC")
        command = New SqlCommand(strQ, con2)
        DA = New SqlDataAdapter(command)
        DS = New DataSet
        DA.Fill(DS, "Table")
        Dim i As Integer = 0
        Dim j As Integer = 0
        'Adds the columns to UserListView
        For i = 0 To DS.Tables(0).Columns.Count - 1
            UserListView.Columns.Add(DS.Tables(0).Columns(i).ColumnName.ToString())
        Next
        'Adds the items to UserListView
        For i = 0 To DS.Tables(0).Rows.Count - 1
            For j = 0 To DS.Tables(0).Columns.Count - 1
                ItemColl(j) = DS.Tables(0).Rows(i)(j).ToString()
            Next
            Dim lvi As New ListViewItem(ItemColl)
            UserListView.Items.Add(lvi)
            Dim lviimage As New ListViewItem(ItemColl)

        Next




Any help would be greatly appreciated!

Thanks!

解决方案

Major part of this question has been asked so many times that it would be bad to answer it again. Please see: http://www.codeproject.com/search.aspx?q=database+store+%28bitmaps+OR+images+OR+pictures%29+%28%22ADO.NET%22+OR+%22C%23%22+OR+%22VB.NET%22%29&doctypeid=1%3b5[^].

In many cases, such as with Web sites/application, it would be more practical to store just the image names and store the images themselves in the file system on server side.

Remaining problem is showing images in ListView. But the problem is: you did not specify which type do you mean, exactly. There are different unrelated (but similar) types using this name as a simple type name, so which one? I don't want any guesswork. Always specify full type name. Better yet, just read documentation on this type.

[EDIT]

As to presenting images in the instance of System.Windows.Forms.ListView, you can get the idea in this MSDN articles:
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.smallimagelist%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.largeimagelist%28v=vs.110%29.aspx[^].

Main thing here is: you have to collect all images in one object of the type System.Windows.Forms.ImageList, the property of the ListView. Then the images shown in the list view will be defined by the indices assigned to the property ImageIndex of the item.

The presentation of the list view depends on the value of View property:
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.view%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.view%28v=vs.110%29.aspx[^].

—SA


这篇关于如何将图像添加到listviewbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆