19-07-23, 11:19 PM
السلام عليكم يوجد لدي اصناف داخل صور داخل ListView عندم اقوم بالضغط على الصورة يقوم الكود بقص ال ID المكتوب داخل الصورة وحذف اسم المنتج ثم البحث عن اسعاره بقاعدة البيانات .. علما بان الكود ياخذ وقت طويل هل يوجد طريقة اسهل ؟
'< بصور المنتجات Listview تعبئة ال
Sub Showimageinlistview()
ListView2.Clear()
Dim dp As New OleDbDataAdapter("SELECT * FROM Proudect", conn)
Dim ds As New DataSet
dp.Fill(ds)
Dim ImageList As New ImageList
ListView2.LargeImageList = ImageList
ImageList.ImageSize = New Size(100, 100)
For x As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim m As Integer = ds.Tables(0).Rows(x)(0)
Dim lb() As Byte = ds.Tables(0).Rows(x).Item("pic")
Dim lstr As New System.IO.MemoryStream(lb)
ImageList.Images.Add(Image.FromStream(lstr), Color.White)
lstr.Close()
Dim ss As String = ds.Tables(0).Rows(x).Item(1)
Dim Lvi As New ListViewItem(ss)
With Lvi
.Text = ds.Tables(0).Rows(x).Item(0) & " " & "-" & ds.Tables(0).Rows(x).Item(1) & ds.Tables(0).Rows(x).Item(2)
.ImageIndex = x
End With
ListView2.Items.Add(Lvi)
Next
'< البحث عن تفاصيل المنتج الذي تم تحديده وفتح قائمة اضافة عدد وسعر المنتج
Private Sub ListView2_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles ListView2.ItemSelectionChanged
TX1.Text = e.Item.Text
Dim mystr As String = TX1.Text
Dim cut_at As String = "-"
Dim y As Integer = InStr(mystr, cut_at)
Dim string_before As String = mystr.Substring(0, y - 2)
Dim string_after As String = mystr.Substring(y + cut_at.Length - 1)
TX1.Text = string_before
Dim dp As New OleDbDataAdapter("select * from Proudect where ID =" & TX1.Text & " ", conn)
Dim ds As New DataSet
dp.Fill(ds)
If ds.Tables(0).Rows.Count <> 0 Then
Button1.Text = ds.Tables(0).Rows(0).Item("price1")
Button2.Text = ds.Tables(0).Rows(0).Item("price2")
END IF
'< بصور المنتجات Listview تعبئة ال
Sub Showimageinlistview()
ListView2.Clear()
Dim dp As New OleDbDataAdapter("SELECT * FROM Proudect", conn)
Dim ds As New DataSet
dp.Fill(ds)
Dim ImageList As New ImageList
ListView2.LargeImageList = ImageList
ImageList.ImageSize = New Size(100, 100)
For x As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim m As Integer = ds.Tables(0).Rows(x)(0)
Dim lb() As Byte = ds.Tables(0).Rows(x).Item("pic")
Dim lstr As New System.IO.MemoryStream(lb)
ImageList.Images.Add(Image.FromStream(lstr), Color.White)
lstr.Close()
Dim ss As String = ds.Tables(0).Rows(x).Item(1)
Dim Lvi As New ListViewItem(ss)
With Lvi
.Text = ds.Tables(0).Rows(x).Item(0) & " " & "-" & ds.Tables(0).Rows(x).Item(1) & ds.Tables(0).Rows(x).Item(2)
.ImageIndex = x
End With
ListView2.Items.Add(Lvi)
Next
'< البحث عن تفاصيل المنتج الذي تم تحديده وفتح قائمة اضافة عدد وسعر المنتج
Private Sub ListView2_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles ListView2.ItemSelectionChanged
TX1.Text = e.Item.Text
Dim mystr As String = TX1.Text
Dim cut_at As String = "-"
Dim y As Integer = InStr(mystr, cut_at)
Dim string_before As String = mystr.Substring(0, y - 2)
Dim string_after As String = mystr.Substring(y + cut_at.Length - 1)
TX1.Text = string_before
Dim dp As New OleDbDataAdapter("select * from Proudect where ID =" & TX1.Text & " ", conn)
Dim ds As New DataSet
dp.Fill(ds)
If ds.Tables(0).Rows.Count <> 0 Then
Button1.Text = ds.Tables(0).Rows(0).Item("price1")
Button2.Text = ds.Tables(0).Rows(0).Item("price2")
END IF

