help1.png

it hard for me to explain what the problem, but the thing that i need your help is , how to retrieve the ID to listview,
im trying to create a POS project like on restaurant or fastfood store, in the listview it will retrieve image ang name, but if listview is click the image will copy to picturebox, the name will copy to textbox1 and the ID will copy to textbox , use the ID the name and picture can be change to update,
please help me how to get the ID

Recommended Answers

All 8 Replies

I only put this code in to my listview

Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged

    If ListView1.SelectedItems.Count > 0 Then
        With ListView1.SelectedItems.Item(0)
            TextBox1.Text = ListView1.SelectedItems(0).Text
            '      TextBox2.Text = ListView1.SelectedItems(1).Text

            PictureBox1.Image = ListView1.LargeImageList.Images(e.Item.ImageKey)
        End With
    End If
End Sub

theres the time that i cant edit may last post
and i thinking if the person didnt understand the post, they will not read it
and if i add some post they will not look at it beacuse they alreardy didnt understand the previouse post

commented: If you feel a post is a lost cause, you can ask for it's removal otherwise it's like you are repeating, repeating, +15

this is code where listview1 retrieve image and name

Private Sub categorylist()

    '  ListView2.Items.Clear()
    cn = New MySqlConnection(constr)
    '  cn.Open()
    cmd = New MySqlCommand
    cmd.Connection = cn
    cmd.CommandText = "Select * from category"
    da = New MySqlDataAdapter(cmd)

    Try
        ListView1.Clear()
        Dim imglist As New ImageList
        imglist.ColorDepth = ColorDepth.Depth32Bit
        ListView1.LargeImageList = imglist
        ListView1.LargeImageList.ImageSize = New System.Drawing.Size(100, 100)
        constr = "select * from category"

        Dim dt_images As New DataTable

        '   cmd.Connection = cn
        cmd.CommandText = constr
        da.SelectCommand = cmd

        da.Fill(dt_images)
        For Each dr As DataRow In dt_images.Rows
            Dim img_buffer = CType(dr("IMG"), Byte())

            Dim img_stream As New MemoryStream(img_buffer, True)

            img_stream.Write(img_buffer, 0, img_buffer.Length)
            imglist.Images.Add(dr("ID").ToString(), New Bitmap(img_stream))
            img_stream.Close()

            Dim lsvparent As New ListViewItem

            lsvparent.Text = dr("IMG").ToString     'if you remove it the system byte will remove to or hide
            lsvparent.ImageKey = dr("ID").ToString       ' if you remoce it the image will hide
            lsvparent.Text = dr("NAME").ToString
            ListView1.Items.Add(lsvparent)
        Next
    Catch ex As Exception
        MsgBox(ex.Message)

    End Try
End Sub

Private Sub ADMIN_ORDER_HOME_Load(sender As Object, e As EventArgs) Handles MyBase.Load
categorylist()
End Sub

im at the part of updating the image and name, thats why i need to get the ID of the DATA
because when i try to update without the ID, its update all the image and name

Private Sub UPDATECATEGORY_Click(sender As Object, e As EventArgs) Handles UPDATECATEGORY.Click

    If TextBox1.Text = "" Then
        'message
    Else
        Dim ms As New MemoryStream  'need to Imports System.IO from general
        PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat) ' save IMAGE
        '  cn = New MySqlConnection(constr)
        cn.Open()
        Dim command As New MySqlCommand("update category set IMG=@IMG  NAME=@NAME", cn)

        With command.Parameters
            .Add("@IMG", MySqlDbType.Blob).Value = ms.ToArray()
        End With
        command.ExecuteNonQuery()
        loadcategory()
        addcategoryclear()
        cn.Close()
    End If
End Sub

hello guys! i already retreive the ID, I use the concept of search
i dont know how to make it nicer,

Private Sub ListView1_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged

    Try
        If ListView1.SelectedItems.Count > 0 Then
            With ListView1.SelectedItems.Item(0)
                TextBox1.Text = ListView1.SelectedItems(0).Text
                PictureBox1.Image = ListView1.LargeImageList.Images(e.Item.ImageKey)
            End With
        End If

        Dim ds As New DataSet
        ds.Clear()
        cn.Open()
        cmd = New MySqlCommand("select ID from category WHERE NAME='" + TextBox1.Text + "'", cn)
        da = New MySqlDataAdapter(cmd)
        da.Fill(ds, "category")
        TextBox4.Text = ds.Tables(0).Rows(0).Item(0)
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        cn.Close()
    End Try

End Sub

a1.png

This post has no text-based content.

I got a problem on image size, when i try to save the image it won't save because of the big size of it, can you help me guys how to rize the image before it save

Private Sub SAVECATEGORY_Click(sender As Object, e As EventArgs) Handles SAVECATEGORY.Click

    If PictureBox1.Image Is Nothing Then
        MessageBox.Show("Please Insert image ")
        addcategoryclear()                              'you call ddcategoryclear()  to clear textbox and picturebox 
    ElseIf TextBox1.Text = "" Then
        MessageBox.Show("Please Insert Image Name")
        addcategoryclear()                              'you call ddcategoryclear()  to clear textbox and picturebox 
    Else
        cn.Open()
        Dim command As New MySqlCommand("INSERT INTO `category`( `IMG`, `NAME`) VALUES (@IMG,@NAME)", cn)

        Dim ms As New MemoryStream  'need to Imports System.IO from general
        PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png) ' save IMAGE

        With command.Parameters
            .Add("@IMG", MySqlDbType.Blob).Value = ms.ToArray()
            .AddWithValue("NAME", TextBox1.Text)
        End With
        If command.ExecuteNonQuery() = 1 Then
            MessageBox.Show("You Successfully Save")

            addcategoryclear() 'you call ddcategoryclear()  to clear textbox and picturebox 
            loadcategory()
        Else
            MessageBox.Show("Something Wrong Pleas Try again")
        End If
        cn.Close()
    End If
    Me.Refresh()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.