Solved

VB.NET Linetype combo box

Posted on 2006-11-12
10
389 Views
Last Modified: 2008-01-09
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
Comment
Question by:TommyTwoPints
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17924864
what do you mean linetype? can you give an example?
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17924883
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
 
LVL 13

Expert Comment

by:newyuppie
ID: 17924901
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 150 total points
ID: 17924960
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
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17924973
newyuppie. i will handle the code that changes the excel cells border. I just need to display the line types in a combo.
0
 
LVL 6

Assisted Solution

by:Marv-in
Marv-in earned 150 total points
ID: 17925023
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
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 200 total points
ID: 17927299
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
 
LVL 10

Expert Comment

by:Kinger247
ID: 17928684
Good work mohzedan !

TommyTwoPints: Remember to reference the System.ComponentModel (in case you haven't)
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17928933
Thanks .. hope it helps him ...
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17930122
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question