Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

VB.NET Linetype combo box

Hi Experts,

I would like to know how i could propulate a combo box with all excels different line types. I could display the linetypes as words, but i'd prefer  to show the actual line type

Cheers.

Tom
0
TommyTwoPints
Asked:
TommyTwoPints
  • 3
  • 2
  • 2
  • +2
3 Solutions
 
newyuppieCommented:
what do you mean linetype? can you give an example?
0
 
TommyTwoPintsAuthor Commented:
in excel, you have the border line types; Single, dashed, dotted etc...

Also a line thickenss combo would be useful (showing the thickness as a graphic rather than an integer)

Cheers,

Tom
0
 
newyuppieCommented:
and you would need this to interact with an Excel cell automatically or would you jsut display the string values and not interact at all with Excel?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Kinger247Commented:
The only way you'll do that is by creating images of the line types and putting them into a listbox used by a combo ..

But you'll need to manually create the line type images (which you could do by taking several screen shots of the line type dropdown).

Here's an example of that in practice : http://www.codeproject.com/vb/net/ImageComboBox_VBNET.asp
0
 
TommyTwoPintsAuthor Commented:
newyuppie. i will handle the code that changes the excel cells border. I just need to display the line types in a combo.
0
 
Marv-inCommented:
I did a simple draw string but you can draw line and change the thikness.

you also need to change the comboboxes drawmode to owner draw

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

        e.DrawBackground()
        e.DrawFocusRectangle()

        e.Graphics.DrawString("-----", Me.Font, Brushes.DarkSlateGray, e.Bounds.Left, e.Bounds.Top)


    End Sub

from article
http://www.codeproject.com/vb/net/xComboBox.asp
0
 
Mohamed ZedanCommented:
I quickly whiped this up for you hope it is what you want :)

Imports System.ComponentModel

Public Class LineTypeCombo
    Inherits ComboBox

    Private _SelectedType As Drawing2D.DashStyle

    Public Sub New()
        MyBase.New()
        MyBase.DrawMode = DrawMode.OwnerDrawFixed
        MyBase.DropDownStyle = ComboBoxStyle.DropDownList
        FillLineTypes()
    End Sub

    Private Sub FillLineTypes()
        Dim Dashs As Drawing.Drawing2D.DashStyle
        Dim Names As String() = [Enum].GetNames(GetType(Drawing2D.DashStyle))
        MyBase.Items.Clear()
        For i As Integer = 0 To Names.Length - 1
            MyBase.Items.Add(Names(i))
        Next

        MyBase.SelectedIndex = 0
        _SelectedType = [Enum].Parse(GetType(Drawing2D.DashStyle), MyBase.Items(0))
    End Sub

    Public ReadOnly Property SelectedLineStyle()
        Get
            Return _SelectedType
        End Get
    End Property

    Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
        MyBase.OnDrawItem(e)
        If e.Index >= 0 Then
            Dim ItemRect As Rectangle = e.Bounds
            Dim Pen As New Pen(Color.Black, 2)
            Pen.DashStyle = [Enum].Parse(GetType(Drawing2D.DashStyle), MyBase.Items(e.Index))

            e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), e.Bounds)

            If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
                e.DrawBackground()
            End If
            If (e.State And DrawItemState.Focus) = DrawItemState.Focus Then
                e.DrawFocusRectangle()
            End If

            e.Graphics.DrawLine(Pen, Convert.ToSingle(ItemRect.X), Convert.ToSingle(ItemRect.Y + ItemRect.Height / 2), _
                                    Convert.ToSingle(ItemRect.X + ItemRect.Width), Convert.ToSingle(ItemRect.Y + ItemRect.Height / 2))
        End If
    End Sub

    Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
        _SelectedType = [Enum].Parse(GetType(Drawing2D.DashStyle), (MyBase.SelectedItem))
        MyBase.OnSelectedIndexChanged(e)
    End Sub

    <Browsable(False)> _
    Public Shadows ReadOnly Property DropDownStyle()
        Get
            Return MyBase.DropDownStyle
        End Get
    End Property 'DropDownStyle
    <Browsable(False)> _
    Public Shadows ReadOnly Property Text()
        Get
            Return MyBase.DropDownStyle
        End Get
    End Property 'Text
    <Browsable(False)> _
        Public Shadows ReadOnly Property Items()
        Get
            Return MyBase.Items
        End Get
    End Property 'Items
    <Browsable(False)> _
        Public Shadows ReadOnly Property DrawMode()
        Get
            Return MyBase.DrawMode
        End Get
    End Property 'DrawMode
    <Browsable(False)> _
        Public Shadows ReadOnly Property DataSource()
        Get
            Return MyBase.DataSource
        End Get
    End Property 'Datasource
    <Browsable(False)> _
        Public Shadows ReadOnly Property DisplayMember()
        Get
            Return MyBase.DisplayMember
        End Get
    End Property 'DisplayMember
    <Browsable(False)> _
            Public Shadows ReadOnly Property ValueMember()
        Get
            Return MyBase.ValueMember
        End Get
    End Property 'ValueMember

    Protected Overrides Sub RefreshItem(ByVal index As Integer)
        MyBase.RefreshItem(index)
    End Sub

    Protected Overrides Sub SetItemsCore(ByVal items As System.Collections.IList)
        MyBase.SetItemsCore(items)
    End Sub

End Class


If you need anything else just ask :)
0
 
Kinger247Commented:
Good work mohzedan !

TommyTwoPints: Remember to reference the System.ComponentModel (in case you haven't)
0
 
Mohamed ZedanCommented:
Thanks .. hope it helps him ...
0
 
TommyTwoPintsAuthor Commented:
Hi guys,

thankyou for your suggestions,

i am actually on holiday until next monday. I will put these suggestions into practice then and accept answer(s) once ive done so,

thank you all,

Tom

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now