Ask a questionAsk a question
 

Answercombobox

  • Tuesday, October 20, 2009 8:16 AMmustangBEL Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    hello

    i want 2 pic in my combobox , which i can select and store in my database.
    how can i do that in vb 2008

Answers

  • Monday, October 26, 2009 7:38 AMMartin Xie - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Thank you MaDFroG for your friendly help.

    Hi mustangBEL,

    Welcome to MSDN forums!

    Question 1: How to Display Images in ComboBox's items in VB.NET?
    Create a New WinForms Project.
    Drag&drop an ImageList control and a ComboBox control from toolbox onto Form1. 
    Go to properties pane of the ImageList and using property collection to add some pictures.
    Then here is code sample Form1.vb:

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

    Dim items(Me.ImageList1.Images.Count - 1) As String

    For i As Int32 = 0 To Me.ImageList1.Images.Count - 1

        items(i) = "Item " & i.ToString

    Next

    Me.ComboBox1.Items.AddRange(items)

    Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

    Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable

    Me.ComboBox1.ItemHeight = Me.ImageList1.ImageSize.Height

    Me.ComboBox1.Width = Me.ImageList1.ImageSize.Width + 18

    Me.ComboBox1.MaxDropDownItems = Me.ImageList1.Images.Count

     

    End Sub

     

     

    Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

     

     If e.Index <> -1 Then

        e.Graphics.DrawImage(Me.ImageList1.Images(e.Index) _

         ,e.Bounds.Left, e.Bounds.Top)

     End If

     

    End Sub

     

     

    Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem

     

     e.ItemHeight = Me.ImageList1.ImageSize.Height

     e.ItemWidth = Me.ImageList1.ImageSize.Width

     

    End Sub

    Trackback: http://www.devasp.net/net/articles/display/365.html 


    This is an extended, owner drawn ComboBox which has an added support to display images in the combobox dropdown as well as the edit (text) box.
    http://www.codeproject.com/KB/combobox/ImageComboBoxControl.aspx 



    Question 2: How do I store BLOB data (e.g. image, document) into the database in VB.NET?

    Storing binary objects (e.g. image, office document etc.) into database is a little cumbersome when it comes to retrieval. Hence the most commonly accepted way is only store the file path in the database, and to store the documents on a file share.
    Trackback: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/e88ae49c-23b3-4160-8138-24d089a3fee1


    If I misunderstood you and you still have any doubt and concern about this issue, please kindly clarify your question to let me know.

     

     

    Best regards,

    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Wednesday, October 21, 2009 2:28 AMMaDFroG20091013 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Would you please be more specific? I can't get your question.
  • Monday, October 26, 2009 7:38 AMMartin Xie - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Thank you MaDFroG for your friendly help.

    Hi mustangBEL,

    Welcome to MSDN forums!

    Question 1: How to Display Images in ComboBox's items in VB.NET?
    Create a New WinForms Project.
    Drag&drop an ImageList control and a ComboBox control from toolbox onto Form1. 
    Go to properties pane of the ImageList and using property collection to add some pictures.
    Then here is code sample Form1.vb:

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

    Dim items(Me.ImageList1.Images.Count - 1) As String

    For i As Int32 = 0 To Me.ImageList1.Images.Count - 1

        items(i) = "Item " & i.ToString

    Next

    Me.ComboBox1.Items.AddRange(items)

    Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

    Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable

    Me.ComboBox1.ItemHeight = Me.ImageList1.ImageSize.Height

    Me.ComboBox1.Width = Me.ImageList1.ImageSize.Width + 18

    Me.ComboBox1.MaxDropDownItems = Me.ImageList1.Images.Count

     

    End Sub

     

     

    Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

     

     If e.Index <> -1 Then

        e.Graphics.DrawImage(Me.ImageList1.Images(e.Index) _

         ,e.Bounds.Left, e.Bounds.Top)

     End If

     

    End Sub

     

     

    Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem

     

     e.ItemHeight = Me.ImageList1.ImageSize.Height

     e.ItemWidth = Me.ImageList1.ImageSize.Width

     

    End Sub

    Trackback: http://www.devasp.net/net/articles/display/365.html 


    This is an extended, owner drawn ComboBox which has an added support to display images in the combobox dropdown as well as the edit (text) box.
    http://www.codeproject.com/KB/combobox/ImageComboBoxControl.aspx 



    Question 2: How do I store BLOB data (e.g. image, document) into the database in VB.NET?

    Storing binary objects (e.g. image, office document etc.) into database is a little cumbersome when it comes to retrieval. Hence the most commonly accepted way is only store the file path in the database, and to store the documents on a file share.
    Trackback: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/e88ae49c-23b3-4160-8138-24d089a3fee1


    If I misunderstood you and you still have any doubt and concern about this issue, please kindly clarify your question to let me know.

     

     

    Best regards,

    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.