DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Custom Controls (Checkbox / List) (http://www.daniweb.com/forums/thread151166.html)

corteplaneta Oct 14th, 2008 5:30 pm
Custom Controls (Checkbox / List)
 
Hi, I'm not too experienced with .NET programming, but I was wondering if anyone knows of a custom control in VB.NET that involves a list (sort of like a ListBox), with at least 2 columns, and the ability to select individual members of this list. I basically have a dynamic NameValueCollection I would like to populate this list with and allow users to select different items.

Does anyone know of a pre-made control like this?

Teme64 Oct 14th, 2008 10:37 pm
Re: Custom Controls (Checkbox / List)
 
You'll get that with ListView control.
Fill ListView control:
Dim TempStr(1) As String
Dim NewNode As ListViewItem
ListView1.View = View.Details
' FullRowSelect has to be True
ListView1.FullRowSelect = True
ListView1.Columns.Clear()
ListView1.Columns.Add("Column1", 100)
ListView1.Columns.Add("Column2", 100)
ListView1.Items.Clear()
TempStr(0) = "foo"
TempStr(1) = "bar"
NewNode = New ListViewItem(TempStr)
ListView1.Items.Add(NewNode)
TempStr(0) = "another"
TempStr(1) = "item"
NewNode = New ListViewItem(TempStr)
ListView1.Items.Add(NewNode)
and check where the mouse was clicked:
Private Sub ListView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
  Dim HTInfo As ListViewHitTestInfo = ListView1.HitTest(e.Location)
  Dim TempStr As String
  HTInfo = ListView1.HitTest(e.Location)
  TempStr = HTInfo.SubItem.ToString
  MessageBox.Show(TempStr, _
    "SubItem", _
    MessageBoxButtons.OK, _
    MessageBoxIcon.Information)
End Sub
Of course you can have more than two columns if you need.

corteplaneta Oct 15th, 2008 10:05 am
Re: Custom Controls (Checkbox / List)
 
Thanks!


All times are GMT -4. The time now is 8:27 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC