لدي ListView وفيه أربع حقول . نوعها نصي بما فيها حقل الصور . ويتم الحفظ فيه بشكل رابط في مجلد pic داخل البرنامج
كما في الصورة التالية
مشكلتي الأن
أريده أن يظهر لي صورة بدل من رابط الصورة
كود الإظافة
كود :
Try
My.Computer.FileSystem.CopyFile(TextBox34.Text, Application.StartupPath & "\pic\" & IO.Path.GetFileName(TextBox34.Text))
Dim AddEditCmd As New OleDbCommand
If Not String.IsNullOrEmpty(Label1.Text) AndAlso Not String.IsNullOrEmpty(TextBox33.Text) AndAlso Not String.IsNullOrEmpty(TextBox32.Text) AndAlso Not String.IsNullOrEmpty(TextBox31.Text) Then
con.Open()
AddEditCmd.Connection = con
AddEditCmd.CommandType = CommandType.Text
AddEditCmd.Parameters.Clear()
AddEditCmd.Parameters.AddWithValue("@E_id", Label1.Text)
AddEditCmd.Parameters.AddWithValue("@E_a", TextBox33.Text)
AddEditCmd.Parameters.AddWithValue("@E_b", TextBox32.Text)
AddEditCmd.Parameters.AddWithValue("@E_c", TextBox31.Text)
AddEditCmd.Parameters.AddWithValue("@E_f", TextBox34.Text)
AddEditCmd.CommandText = "INSERT INTO Tab6([E_id],[E_a],[E_b],[E_c],[E_f]) VALUES(@E_id,@E_a,@E_b,@E_c,'" & IO.Path.GetFileName(TextBox34.Text) & "')"
End If
AddEditCmd.ExecuteNonQuery()
AddEditCmd.Dispose()
con.Close()
وكود عرض ListView
كود :
Dim Itm As ListViewItem
For a As Integer = 0 To data__Leave2.Tables("Tab6").Rows.Count - 1
Try
Dim red As New OpenFileDialog()
red.Filter = "Choose Image(*.jpg; *.png; *.gif)|*.jpg; *.png; *.gif"
If red.ShowDialog() = DialogResult.OK Then
Dim img As New DataGridViewImageColumn
Dim img1 As Image = Image.FromFile(red.FileName)
img.Image = img1
dg.Rows.Add(t1.Text, t2.Text, t3.Text ts.Text, tt.Text, img1)
End If
Catch ex As Exception
For Each itm As ListViewItem In ListViewEx1.Items Dim link As New LinkLabel AddHandler link.LinkClicked, AddressOf LinkLabel_LinkClicked link.Text = "صورة" ' itm.SubItems(1).Text ListViewEx1.AddEmbeddedControl(link, ListViewEx1.Columns(1).Index, itm.Index) Next
ListViewEx1.SelectedItems(0).Selected = True End Sub
Private Sub LinkLabel_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Process.Start(ListViewEx1.SelectedItems(0).SubItems(1).Text) 'MsgBox(ListViewEx1.SelectedItems(0).SubItems(1).Text) End Sub
End Class
#Region "ListViewEx" Public Class ListViewEx Inherits ListView #Region "Interop-Defines" <Runtime.InteropServices.DllImport("user32.dll")> _ Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wPar As IntPtr, ByVal lPar As IntPtr) As IntPtr End Function
' ListView messages Private Const LVM_FIRST As Integer = &H1000 Private Const LVM_GETCOLUMNORDERARRAY As Integer = (LVM_FIRST + 59)
' Windows Messages Private Const WM_PAINT As Integer = &HF #End Region
''' <summary> ''' Structure to hold an embedded control's info ''' </summary> Private Structure EmbeddedControl Public Control As Control Public Column As Integer Public Row As Integer Public Dock As DockStyle Public Item As ListViewItem End Structure
Private _embeddedControls As New ArrayList()
Public Sub New() End Sub
''' <summary> ''' Retrieve the order in which columns appear ''' </summary> ''' <returns>Current display order of column indices</returns> Protected Function GetColumnOrder() As Integer() Dim lPar As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(Runtime.InteropServices.Marshal.SizeOf(GetType(Integer)) * Columns.Count)
Dim res As IntPtr = SendMessage(Handle, LVM_GETCOLUMNORDERARRAY, New IntPtr(Columns.Count), lPar) If res.ToInt32() = 0 Then ' Something went wrong Runtime.InteropServices.Marshal.FreeHGlobal(lPar) Return Nothing End If
Dim order As Integer() = New Integer(Columns.Count - 1) {} Runtime.InteropServices.Marshal.Copy(lPar, order, 0, Columns.Count)
Runtime.InteropServices.Marshal.FreeHGlobal(lPar)
Return order End Function
''' <summary> ''' Retrieve the bounds of a ListViewSubItem ''' </summary> ''' <param name="Item">The Item containing the SubItem</param> ''' <param name="SubItem">Index of the SubItem</param> ''' <returns>Subitem's bounds</returns> Protected Function GetSubItemBounds(ByVal Item As ListViewItem, ByVal SubItem As Integer) As Rectangle Dim subItemRect As Rectangle = Rectangle.Empty
If Item Is Nothing Then Throw New ArgumentNullException("Item") End If
Dim order As Integer() = GetColumnOrder() If order Is Nothing Then ' No Columns Return subItemRect End If
If SubItem >= order.Length Then Throw New IndexOutOfRangeException("SubItem " + SubItem + " out of range") End If
' Retrieve the bounds of the entire ListViewItem (all subitems) Dim lviBounds As Rectangle = Item.GetBounds(ItemBoundsPortion.Entire) Dim subItemX As Integer = lviBounds.Left
' Calculate the X position of the SubItem. ' Because the columns can be reordered we have to use Columns[order[i]] instead of Columns[i] ! Dim col As ColumnHeader Dim i As Integer For i = 0 To order.Length - 1 col = Me.Columns(order(i)) If col.Index = SubItem Then Exit For End If subItemX += col.Width Next
subItemRect = New Rectangle(subItemX, lviBounds.Top, Me.Columns(order(i)).Width, lviBounds.Height)
Return subItemRect End Function
''' <summary> ''' Add a control to the ListView ''' </summary> ''' <param name="c">Control to be added</param> ''' <param name="col">Index of column</param> ''' <param name="row">Index of row</param> Public Sub AddEmbeddedControl(ByVal c As Control, ByVal col As Integer, ByVal row As Integer) AddEmbeddedControl(c, col, row, DockStyle.Fill) End Sub ''' <summary> ''' Add a control to the ListView ''' </summary> ''' <param name="c">Control to be added</param> ''' <param name="col">Index of column</param> ''' <param name="row">Index of row</param> ''' <param name="dock">Location and resize behavior of embedded control</param> Public Sub AddEmbeddedControl(ByVal c As Control, ByVal col As Integer, ByVal row As Integer, ByVal dock As DockStyle) If c Is Nothing Then Throw New ArgumentNullException() End If If col >= Columns.Count OrElse row >= Items.Count Then Throw New ArgumentOutOfRangeException() End If
Dim ec As EmbeddedControl ec.Control = c ec.Column = col ec.Row = row ec.Dock = dock ec.Item = Items(row)
_embeddedControls.Add(ec)
' Add a Click event handler to select the ListView row when an embedded control is clicked AddHandler c.Click, AddressOf _embeddedControl_Click
Me.Controls.Add(c) End Sub
''' <summary> ''' Remove a control from the ListView ''' </summary> ''' <param name="c">Control to be removed</param> Public Sub RemoveEmbeddedControl(ByVal c As Control) If c Is Nothing Then Throw New ArgumentNullException() End If
For i As Integer = 0 To _embeddedControls.Count - 1 Dim ec As EmbeddedControl = CType(_embeddedControls(i), EmbeddedControl) If ec.Control Is c Then RemoveHandler c.Click, AddressOf _embeddedControl_Click Me.Controls.Remove(c) _embeddedControls.RemoveAt(i) Return End If Next Throw New Exception("Control not found!") End Sub
''' <summary> ''' Retrieve the control embedded at a given location ''' </summary> ''' <param name="col">Index of Column</param> ''' <param name="row">Index of Row</param> ''' <returns>Control found at given location or null if none assigned.</returns> Public Function GetEmbeddedControl(ByVal col As Integer, ByVal row As Integer) As Control For Each ec As EmbeddedControl In _embeddedControls If ec.Row = row AndAlso ec.Column = col Then Return ec.Control End If Next
Return Nothing End Function
<System.ComponentModel.DefaultValue(View.LargeIcon)> _ Public Shadows Property View() As View Get Return MyBase.View End Get Set(ByVal value As View) ' Embedded controls are rendered only when we're in Details mode For Each ec As EmbeddedControl In _embeddedControls ec.Control.Visible = (value = View.Details) Next
MyBase.View = value End Set End Property
Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg Case WM_PAINT If View <> View.Details Then Exit Select End If
' Calculate the position of all embedded controls For Each ec As EmbeddedControl In _embeddedControls Dim rc As Rectangle = Me.GetSubItemBounds(ec.Item, ec.Column)
If (Me.HeaderStyle <> ColumnHeaderStyle.None) AndAlso (rc.Top < Me.Font.Height) Then ' Control overlaps ColumnHeader ec.Control.Visible = False Continue For Else ec.Control.Visible = True End If
Select Case ec.Dock Case DockStyle.Fill Exit Select Case DockStyle.Top rc.Height = ec.Control.Height Exit Select Case DockStyle.Left rc.Width = ec.Control.Width Exit Select Case DockStyle.Bottom rc.Offset(0, rc.Height - ec.Control.Height) rc.Height = ec.Control.Height Exit Select Case DockStyle.Right rc.Offset(rc.Width - ec.Control.Width, 0) rc.Width = ec.Control.Width Exit Select Case DockStyle.None rc.Size = ec.Control.Size Exit Select End Select
' Set embedded control's bounds ec.Control.Bounds = rc Next Exit Select End Select MyBase.WndProc(m) End Sub
Private Sub _embeddedControl_Click(ByVal sender As Object, ByVal e As EventArgs) ' When a control is clicked the ListViewItem holding it is selected For Each ec As EmbeddedControl In _embeddedControls If ec.Control Is DirectCast(sender, Control) Then Me.SelectedItems.Clear() ec.Item.Selected = True End If Next End Sub End Class
(07-01-16, 12:52 AM)حريف برمجة كتب : وعليكم السلام ورحمة الله وبركاته
اقترح عليك استبدل الليست فيو بداتا قريد فيو ..
جميل جداً وبيمشي تمام ولكني جعلته أخر الحلول
(07-01-16, 06:11 AM)الماجيك مسعد كتب : Try
Dim red As New OpenFileDialog()
red.Filter = "Choose Image(*.jpg; *.png; *.gif)|*.jpg; *.png; *.gif"
If red.ShowDialog() = DialogResult.OK Then
Dim img As New DataGridViewImageColumn
Dim img1 As Image = Image.FromFile(red.FileName)
img.Image = img1
dg.Rows.Add(t1.Text, t2.Text, t3.Text ts.Text, tt.Text, img1)
End If
Catch ex As Exception
End Try
أشكرك أخي الكريم ولكن هذا الكود للداتاقريد وليس لليست فيو تحياتي
(07-01-16, 06:53 AM)sami2015 كتب :
PHP كود :
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each itm As ListViewItem In ListViewEx1.Items Dim link As New LinkLabel AddHandler link.LinkClicked, AddressOf LinkLabel_LinkClicked link.Text = "صورة" ' itm.SubItems(1).Text ListViewEx1.AddEmbeddedControl(link, ListViewEx1.Columns(1).Index, itm.Index) Next
ListViewEx1.SelectedItems(0).Selected = True End Sub
Private Sub LinkLabel_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Process.Start(ListViewEx1.SelectedItems(0).SubItems(1).Text) 'MsgBox(ListViewEx1.SelectedItems(0).SubItems(1).Text) End Sub
End Class
#Region "ListViewEx" Public Class ListViewEx Inherits ListView #Region "Interop-Defines" <Runtime.InteropServices.DllImport("user32.dll")> _ Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wPar As IntPtr, ByVal lPar As IntPtr) As IntPtr End Function
' ListView messages Private Const LVM_FIRST As Integer = &H1000 Private Const LVM_GETCOLUMNORDERARRAY As Integer = (LVM_FIRST + 59)
' Windows Messages Private Const WM_PAINT As Integer = &HF #End Region
''' <summary> ''' Structure to hold an embedded control's info ''' </summary> Private Structure EmbeddedControl Public Control As Control Public Column As Integer Public Row As Integer Public Dock As DockStyle Public Item As ListViewItem End Structure
Private _embeddedControls As New ArrayList()
Public Sub New() End Sub
''' <summary> ''' Retrieve the order in which columns appear ''' </summary> ''' <returns>Current display order of column indices</returns> Protected Function GetColumnOrder() As Integer() Dim lPar As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(Runtime.InteropServices.Marshal.SizeOf(GetType(Integer)) * Columns.Count)
Dim res As IntPtr = SendMessage(Handle, LVM_GETCOLUMNORDERARRAY, New IntPtr(Columns.Count), lPar) If res.ToInt32() = 0 Then ' Something went wrong Runtime.InteropServices.Marshal.FreeHGlobal(lPar) Return Nothing End If
Dim order As Integer() = New Integer(Columns.Count - 1) {} Runtime.InteropServices.Marshal.Copy(lPar, order, 0, Columns.Count)
Runtime.InteropServices.Marshal.FreeHGlobal(lPar)
Return order End Function
''' <summary> ''' Retrieve the bounds of a ListViewSubItem ''' </summary> ''' <param name="Item">The Item containing the SubItem</param> ''' <param name="SubItem">Index of the SubItem</param> ''' <returns>Subitem's bounds</returns> Protected Function GetSubItemBounds(ByVal Item As ListViewItem, ByVal SubItem As Integer) As Rectangle Dim subItemRect As Rectangle = Rectangle.Empty
If Item Is Nothing Then Throw New ArgumentNullException("Item") End If
Dim order As Integer() = GetColumnOrder() If order Is Nothing Then ' No Columns Return subItemRect End If
If SubItem >= order.Length Then Throw New IndexOutOfRangeException("SubItem " + SubItem + " out of range") End If
' Retrieve the bounds of the entire ListViewItem (all subitems) Dim lviBounds As Rectangle = Item.GetBounds(ItemBoundsPortion.Entire) Dim subItemX As Integer = lviBounds.Left
' Calculate the X position of the SubItem. ' Because the columns can be reordered we have to use Columns[order[i]] instead of Columns[i] ! Dim col As ColumnHeader Dim i As Integer For i = 0 To order.Length - 1 col = Me.Columns(order(i)) If col.Index = SubItem Then Exit For End If subItemX += col.Width Next
subItemRect = New Rectangle(subItemX, lviBounds.Top, Me.Columns(order(i)).Width, lviBounds.Height)
Return subItemRect End Function
''' <summary> ''' Add a control to the ListView ''' </summary> ''' <param name="c">Control to be added</param> ''' <param name="col">Index of column</param> ''' <param name="row">Index of row</param> Public Sub AddEmbeddedControl(ByVal c As Control, ByVal col As Integer, ByVal row As Integer) AddEmbeddedControl(c, col, row, DockStyle.Fill) End Sub ''' <summary> ''' Add a control to the ListView ''' </summary> ''' <param name="c">Control to be added</param> ''' <param name="col">Index of column</param> ''' <param name="row">Index of row</param> ''' <param name="dock">Location and resize behavior of embedded control</param> Public Sub AddEmbeddedControl(ByVal c As Control, ByVal col As Integer, ByVal row As Integer, ByVal dock As DockStyle) If c Is Nothing Then Throw New ArgumentNullException() End If If col >= Columns.Count OrElse row >= Items.Count Then Throw New ArgumentOutOfRangeException() End If
Dim ec As EmbeddedControl ec.Control = c ec.Column = col ec.Row = row ec.Dock = dock ec.Item = Items(row)
_embeddedControls.Add(ec)
' Add a Click event handler to select the ListView row when an embedded control is clicked AddHandler c.Click, AddressOf _embeddedControl_Click
Me.Controls.Add(c) End Sub
''' <summary> ''' Remove a control from the ListView ''' </summary> ''' <param name="c">Control to be removed</param> Public Sub RemoveEmbeddedControl(ByVal c As Control) If c Is Nothing Then Throw New ArgumentNullException() End If
For i As Integer = 0 To _embeddedControls.Count - 1 Dim ec As EmbeddedControl = CType(_embeddedControls(i), EmbeddedControl) If ec.Control Is c Then RemoveHandler c.Click, AddressOf _embeddedControl_Click Me.Controls.Remove(c) _embeddedControls.RemoveAt(i) Return End If Next Throw New Exception("Control not found!") End Sub
''' <summary> ''' Retrieve the control embedded at a given location ''' </summary> ''' <param name="col">Index of Column</param> ''' <param name="row">Index of Row</param> ''' <returns>Control found at given location or null if none assigned.</returns> Public Function GetEmbeddedControl(ByVal col As Integer, ByVal row As Integer) As Control For Each ec As EmbeddedControl In _embeddedControls If ec.Row = row AndAlso ec.Column = col Then Return ec.Control End If Next
Return Nothing End Function
<System.ComponentModel.DefaultValue(View.LargeIcon)> _ Public Shadows Property View() As View Get Return MyBase.View End Get Set(ByVal value As View) ' Embedded controls are rendered only when we're in Details mode For Each ec As EmbeddedControl In _embeddedControls ec.Control.Visible = (value = View.Details) Next
MyBase.View = value End Set End Property
Protected Overrides Sub WndProc(ByRef m As Message) Select Case m.Msg Case WM_PAINT If View <> View.Details Then Exit Select End If
' Calculate the position of all embedded controls For Each ec As EmbeddedControl In _embeddedControls Dim rc As Rectangle = Me.GetSubItemBounds(ec.Item, ec.Column)
If (Me.HeaderStyle <> ColumnHeaderStyle.None) AndAlso (rc.Top < Me.Font.Height) Then ' Control overlaps ColumnHeader ec.Control.Visible = False Continue For Else ec.Control.Visible = True End If
Select Case ec.Dock Case DockStyle.Fill Exit Select Case DockStyle.Top rc.Height = ec.Control.Height Exit Select Case DockStyle.Left rc.Width = ec.Control.Width Exit Select Case DockStyle.Bottom rc.Offset(0, rc.Height - ec.Control.Height) rc.Height = ec.Control.Height Exit Select Case DockStyle.Right rc.Offset(rc.Width - ec.Control.Width, 0) rc.Width = ec.Control.Width Exit Select Case DockStyle.None rc.Size = ec.Control.Size Exit Select End Select
' Set embedded control's bounds ec.Control.Bounds = rc Next Exit Select End Select MyBase.WndProc(m) End Sub
Private Sub _embeddedControl_Click(ByVal sender As Object, ByVal e As EventArgs) ' When a control is clicked the ListViewItem holding it is selected For Each ec As EmbeddedControl In _embeddedControls If ec.Control Is DirectCast(sender, Control) Then Me.SelectedItems.Clear() ec.Item.Selected = True End If Next End Sub End Class
#End Region
شكراً لك أخي الكريم جاري التجربة وإنشالله يحقق مطلبي أشكرك تحياتي
For Each itm As ListViewItem In ListViewEx1.Items Dim pic As New PictureBox pic.Cursor = Cursors.Hand pic.SizeMode = PictureBoxSizeMode.Zoom AddHandler pic.Click, AddressOf PictureBox_Click pic.ImageLocation = itm.SubItems(picColIndx).Text pic.Tag = itm.SubItems(picColIndx).Text ListViewEx1.AddEmbeddedControl(pic, ListViewEx1.Columns(picColIndx).Index, itm.Index) Next
End Sub
Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Process.Start(sender.Tag) 'MsgBox(sender.Tag) End Sub
السلام عليكم ورحمة الله وبركاتة
الأخ العزيز ده مثال بسيط عن إضافة الصور من ملف إلى اللست فيو وهتلاقي بعض العمليات البسيطة كالتالي :
1- إضافة ملف أو عدة ملفات
2-إضافة مجلد كامل
3- فتح الصور في فورم جديد عند الدبل كليك
4- حذف الملفات المحددة في اللست فيو
For Each itm As ListViewItem In ListViewEx1.Items Dim pic As New PictureBox pic.Cursor = Cursors.Hand pic.SizeMode = PictureBoxSizeMode.Zoom AddHandler pic.Click, AddressOf PictureBox_Click pic.ImageLocation = itm.SubItems(picColIndx).Text pic.Tag = itm.SubItems(picColIndx).Text ListViewEx1.AddEmbeddedControl(pic, ListViewEx1.Columns(picColIndx).Index, itm.Index) Next
End Sub
Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Process.Start(sender.Tag) 'MsgBox(sender.Tag) End Sub
End Class
أشكرك أخي سامي تعبتك معاي لاحرمك الله الاجر
أفدتني
(08-01-16, 01:41 AM)HASAN6.0 كتب : انا اضيف imagelist واضيف الصور بداخلها ..
واعمل new listviewitem
واقوم بضبط imagekey لاسم الصورة في الـimagelist فقط
فكرة جميلة لم أفكر بها جزاك الله خير
(08-01-16, 04:09 AM)ممدوح الخطيب كتب : السلام عليكم ورحمة الله وبركاتة
الأخ العزيز ده مثال بسيط عن إضافة الصور من ملف إلى اللست فيو وهتلاقي بعض العمليات البسيطة كالتالي :
1- إضافة ملف أو عدة ملفات
2-إضافة مجلد كامل
3- فتح الصور في فورم جديد عند الدبل كليك
4- حذف الملفات المحددة في اللست فيو