Solved

VB.NET MultiColumn CheckedListBox

Posted on 2004-09-13
8
6,901 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

17 Experts available now in Live!

Get 1:1 Help Now