CheckedListBox making textbox visible

Having problem making selected index from checkedlistbox turn specific

Page 1 of 1

7 Replies - 3714 Views - Last Post: 13 December 2009 - 10:58 PM Rate Topic: -----

#1 MonkeyThrottle.Com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 09

CheckedListBox making textbox visible

Post icon  Posted 13 December 2009 - 08:14 PM

My question to y'all is this....I have a CheckedListBox with 6 different indices that all correspond to a textBox. For example: Index 0 corresponds with TextBox1, Index 1 corresponds with TextBox2, and so forth. When the user selects the item in the CheckedListBox, the TextBox with that particular index becomes visible. I am at a loss. I have been working on this for 4 days now, with no end in sight! Thank y'all for your time!


  Private Sub clstLinks_ItemCheck(ByVal sender As System.Object, ByVal e As ItemCheckEventArgs) Handles clstLinks.ItemCheck


		txt1.Visible = False
		txt2.Visible = False
		txt3.Visible = False
		txt4.Visible = False
		txt5.Visible = False
		txt6.Visible = False



		If e.CurrentValue = CheckState.Unchecked Then
			txt1.Visible = True
		Else
			txt1.Visible = False
		End If

		If e.NewValue = CheckState.Checked Then
			txt2.Visible = True
		Else
			txt2.Visible = False
		End If


	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: CheckedListBox making textbox visible

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,010
  • Joined: 02-July 08

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 08:42 PM

Make an array of textboxes:
Private TList() As TextBox

Load event fill the array:
TList = New TextBox() {TextBox1, TextBox2, TextBox3, TextBox4}

Then in your ItemClicked event:
If e.NewValue = CheckState.Checked Then
	  TList(e.Index).Visible = False
Else
	  TList(e.Index).Visible = True
End If

Was This Post Helpful? 1
  • +
  • -

#3 MonkeyThrottle.Com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 09

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 08:56 PM

Thank you so much! I didn't think you could still do that...especially on the newer versions of VB!

Now my question to you is, is there any way to seperate it? For example if a user checks items 1, 4, 5 then the TextBoxes 1, 4, 5 should be visible. The others are hidden. Would a For...Next Statement work in this situation such as:

For Each CheckedListBox1.CheckedItemCollection

Next


This is where I am totally confused! Thank you once again for your help!
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,010
  • Joined: 02-July 08

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 09:33 PM

Not sure what you mean my example does just that as is. ???
Was This Post Helpful? 0
  • +
  • -

#5 MonkeyThrottle.Com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 09

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 09:42 PM

Here is the code I am running...
Private Sub clstLinks_ItemCheck(ByVal sender As System.Object, ByVal e As ItemCheckEventArgs) Handles clstLinks.ItemCheck

		Dim txtAll As TextBox() = New TextBox() {txt1, txt2, txt3, txt4, txt5, txt6}



		clstLinks.GetItemChecked(e.Index)

		If e.NewValue = CheckState.Checked Then
			txtAll(e.Index).Visible = True
		Else
			txtAll(e.Index).Visible = False
		End If

	End Sub


What is happening is that I am only able to return one TextBox. I cannot use the Multi-Select or Multi-Extended Property because of the CheckedListBox. We are supposed to have more than one TextBox enabled. I am not sure what to do from there.
Was This Post Helpful? 0
  • +
  • -

#6 MonkeyThrottle.Com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 09

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 09:50 PM

The problem I'm having is when I click on more than one of the check boxes, it's returning the value of the last check box. If I click on 1, 3, and 6, it returns the TextBox for item 6.
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,010
  • Joined: 02-July 08

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 10:04 PM

More like this:
Public Class blah
   Private TList() As TextBox
   Private Sub Form1_Load(...)
	   TList = New TextBox() {TextBox1, TextBox2, TextBox3, TextBox4}
   End Sub
   Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
	 If e.NewValue = CheckState.Checked Then
		TList(e.Index).Visible = True
	 Else
		TList(e.Index).Visible = False
	 End If
   End Sub
End Class 'blah

My example uses SelectionMode/one
Was This Post Helpful? 1
  • +
  • -

#8 MonkeyThrottle.Com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 09

Re: CheckedListBox making textbox visible

Posted 13 December 2009 - 10:58 PM

THANK YOU SO MUCH FOR YOUR GUIDANCE!!!!

I worked and worked and finally got this code to work! I don't think it's exactly what I needed to do, but IT WORKS!!! LOL

Here is my FINAL code:

Public Class Form1


	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		txt1.Visible = False
		txt2.Visible = False
		txt3.Visible = False
		txt4.Visible = False
		txt5.Visible = False
		txt6.Visible = False

	End Sub
	Private Sub clstLinks_ItemCheck(ByVal sender As System.Object, ByVal e As ItemCheckEventArgs) Handles clstLinks.ItemCheck



		Dim txtAll() As TextBox = New TextBox() {txt1, txt2, txt3, txt4, txt5, txt6}

		If e.NewValue = CheckState.Checked Then
			txtAll(e.Index).Visible = True
		Else
			txtAll(e.Index).Visible = False
		End If
	End Sub


End Class



Once again, HawkValley1...THANK YOU SO MUCH!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1