Solved

VB.NET MultiColumn CheckedListBox

Posted on 2004-09-13
8
6,930 Views
Last Modified: 2012-08-14
Hi all. As I'm upgrading to vb.NET, I need help making a MultiColumn CheckedListBox, first column would have squares containing colors (or just the background color of the item) so by clicking them I call the colorBox to change the color; the second column would have RichTextBox (so every item can display symbols, colors...).
I assume I need to make a user-control and when the checkedListBox is changed; I would need to make a new richTextBox in the second column of that item...
I appreciate any help.

I know how to access a row, how can I access a column ?
Is there any way I can have two columns with different widths ?
0
Comment
Question by:Dan-Key
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12051241
Try the windows forms listview control

0
 

Author Comment

by:Dan-Key
ID: 12066939
This is not the expected result.
        ListView1.Columns.Add("color1", 20, HorizontalAlignment.Left)
        ListView1.Items.Add("Text" & ListView1.Items.Count & " is here")
It does not appear with a checkBox ! and I can not set BackColor a specific item in the first column...It automatically puts columns at the next row, or puts new rows at the new column but asme row !
I still think maybe a checkedListBox would work.
Please comment with some details. Thanks.
0
 
LVL 10

Accepted Solution

by:
prakash_prk earned 250 total points
ID: 12071906
Hi Dan-key
                I doesn't know your exact requierment so that i only said "try the listview control" sorry for that.
Try this code
------------------
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Color As System.Windows.Forms.ColumnHeader
    Friend WithEvents SomeText As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"", "There is a text"}, -1, System.Drawing.Color.Empty, System.Drawing.Color.Brown, Nothing)
        Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"", "hai"}, -1, System.Drawing.Color.Empty, System.Drawing.Color.Orange, Nothing)
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Color = New System.Windows.Forms.ColumnHeader
        Me.SomeText = New System.Windows.Forms.ColumnHeader
        Me.SuspendLayout()
        '
        'ListView1
        '
        Me.ListView1.CheckBoxes = True
        Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.Color, Me.SomeText})
        Me.ListView1.FullRowSelect = True
        ListViewItem1.StateImageIndex = 0
        ListViewItem1.UseItemStyleForSubItems = False
        ListViewItem2.StateImageIndex = 0
        ListViewItem2.UseItemStyleForSubItems = False
        Me.ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2})
        Me.ListView1.Location = New System.Drawing.Point(72, 104)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(176, 97)
        Me.ListView1.TabIndex = 0
        Me.ListView1.View = System.Windows.Forms.View.Details
        '
        'Color
        '
        Me.Color.Text = "Color"
        Me.Color.Width = 75
        '
        'SomeText
        '
        Me.SomeText.Text = "Text"
        Me.SomeText.Width = 86
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.ListView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

    End Sub

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

    End Sub
End Class
--------------------
Check this link
http://www.c-sharpcorner.com//Code/2002/July/EditableListView.asp


regards
prakash
0
 

Author Comment

by:Dan-Key
ID: 12086434
Hi prakash. You sample is very very close to what I want.
Would you please let me know, how to do the following:
To add an item this does not work:
        ListView1.Items.Add("")
        ListView1.Items(ListView1.Items.Count - 1).SubItems(0).BackColor = System.Drawing.Color.Red
        ListView1.Items(ListView1.Items.Count - 1).SubItems(1).Text = "new item"


Also, if anyone knows how to put an image in a third item, that would be great.
Thanks a lot.
Regards, Dan-Key
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Dan-Key
ID: 12090374
Hi. The following works:
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add("New item", Drawing.Color.Black, Drawing.Color.White, ListView1.Font)

About having a picture in an item, I'll try. Any futher help would be appreciated.
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12090413
Add a imagelist control
Add images to it .

Then set the LargeImageList to imagelist you added

Add items set the state image index

regards
prakash
0
 

Author Comment

by:Dan-Key
ID: 12094145
Prakash, Thanks to you. ListView is useful...
Have a great time.
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12099284
Thank you Dan-Key

regards
prakash
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now