Solved

VB.NET Linetype combo box

Posted on 2006-11-12
10
377 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Suggested Solutions

Title # Comments Views Activity
VB.Net - Get ColumnNames of SQL Table 4 15
Get number of Files in Directory and Sub Directories 2 48
Iteration Help (Asp.net VB) 5 24
Optimize the query 5 43
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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