11 Replies - 3225 Views - Last Post: 15 March 2013 - 02:20 PM Rate Topic: -----

#1 koppong  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-March 13

Checkboxes display the same values

Posted 14 March 2013 - 09:26 PM

I have 4 checkboxes that are linked to a listview. Anytime I select a checkbox the listview popup and I am able to select a value in a cell which is then displayed in txtbox1. THe problem I am having now is: A second checkbox also displays a value in txtbox2 and automatical textbox1 value changes to have the same value as the txtbox2. This is not my initial plan.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Form1.CheckBox1.Checked = True Then
            Form1.txtLeak.Text = Label5.Text
        End If
        If Form1.CheckBox2.Checked = True Then
            Form1.txtSidescatter.Text = Label5.Text
        End If
        If Form1.CheckBox3.Checked = True Then
            Form1.txtLeakageSideScatter.Text = Label5.Text
        End If
        If Form1.CheckBox4.Checked = True Then
            Form1.txtForwardBackscatter.Text = Label5.Text
        End If
        If Form1.CheckBox5.Checked = True Then
            Form1.txtLeakageForward.Text = Label5.Text
        End If
        Close()

    End Sub 


Is This A Good Question/Topic? 0
  • +

Replies To: Checkboxes display the same values

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Checkboxes display the same values

Posted 14 March 2013 - 09:48 PM

I don't see any reference to TextBox1 or TextBox2. All I see is that when you click Button1, you will place a values in TextBoxes, and no matter which CheckBox (or CheckBoxes) you have checked, one or more TextBoxes will get whatever is in Label5.Text.
I doubt this is your intention, but that's what the code says.
Was This Post Helpful? 0
  • +
  • -

#3 koppong  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-March 13

Re: Checkboxes display the same values

Posted 14 March 2013 - 10:05 PM

sorry the txtboxes names are the : txtLeak, txtSidescatter, and txtLeakageSideScatter
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Checkboxes display the same values

Posted 14 March 2013 - 10:26 PM

View Postkoppong, on 14 March 2013 - 11:05 PM, said:

sorry the txtboxes names are the : txtLeak, txtSidescatter, and txtLeakageSideScatter

OK, but the fact remains that all Button1 will do is to put the string contained in Label5.Text into one or more of your TextBoxes.

To be perfectly clear, let's assume Label5.Text contains the String "1234", and that CheckBox2 and CheckBox4 are both checked. When you click Button 1, txtSidescatter.Text and txtForwardBackscatter.Text will BOTH contain "1234".

Is this your intention?
Was This Post Helpful? 0
  • +
  • -

#5 koppong  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-March 13

Re: Checkboxes display the same values

Posted 14 March 2013 - 10:52 PM

No, I want each box to contain different values when a user select a different cell in a listview and clicks on the button.
for instance: If I check Checkbox1, a listview is opened. Then I select cell 'a'=ABC in the listview, the value is put in label5. And when I click on button1, the value ABC is placed in the txtLeak.
Now I select checkbox2, and I select cell 'D' = KEF, the value is put in label 5. And when I click on button1, the valued KEF is placed in txtSidescatter
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Checkboxes display the same values

Posted 14 March 2013 - 11:14 PM

View Postkoppong, on 14 March 2013 - 11:52 PM, said:

No, I want each box to contain different values when a user select a different cell in a listview and clicks on the button.
for instance: If I check Checkbox1, a listview is opened. Then I select cell 'a'=ABC in the listview, the value is put in label5. And when I click on button1, the value ABC is placed in the txtLeak.
Now I select checkbox2, and I select cell 'D' = KEF, the value is put in label 5. And when I click on button1, the valued KEF is placed in txtSidescatter

OK, but I don't see any code for getting the strings to put into Label5.

As it stands, the code you supplied will certainly place a value in a TextBox selected by the CheckBox that is checked, but it will do so for all CheckBoxes that are checked. All of them. If all CheckBoxes are checked, all the TextBoxes will end up with the same value, from Label5.Text.

You do realize that CheckBoxes are not mutually exclusive, don't you? They are not like RadioButtons, where only one in a group may be active (on).
Was This Post Helpful? 0
  • +
  • -

#7 koppong  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-March 13

Re: Checkboxes display the same values

Posted 15 March 2013 - 12:14 PM

You right!, I figured it out but bereft of idea. If anyone has an Idea about how to go by it. For the textboxes must be filled and the values summed up.
Was This Post Helpful? 0
  • +
  • -

#8 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Checkboxes display the same values

Posted 15 March 2013 - 12:34 PM

OK, first of all, as I mentioned before, I don't see your code to select the data, so I can't be too sure of just what sort of GUI you are trying to create. It would help if you could give us a better idea of how you choose the data, and posting some code is the best way. For example, do you have multiple ListViews? Are the checkboxes part of the ListView(s)?

I do know that using a CheckBox to trigger a popup is probably not the best design decision. As well, is there some reason you want to use a label as a variable? It's REALLY bad practice. The second part of that is that you are using the same Label to temporarily hold the data destined for four different TextBoxes.

No matter what selection method you use to let the user choose the data, you should put that data into a variable, or directly into the TextBox. For example, You select the data that's destined for txtBackScatter... why not put it into a String variable called somthing like strBackScatter? If you don't need to display it, there's no need to place it in the TextBox. If you do need to display it, you could put it directly into txtBackScatter. And there's nothing to say you can't put it into both a variable and a TextBox. Just bear in mind that controls are for the GUI, and variables are for working with data.

This post has been edited by lar3ry: 15 March 2013 - 12:37 PM

Was This Post Helpful? 0
  • +
  • -

#9 koppong  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-March 13

Re: Checkboxes display the same values

Posted 15 March 2013 - 01:20 PM

I want each box to contain different values when a user select a different cell in a listview and clicks on the button.
for instance: If I check Checkbox1, a listview is opened. Then I select cell 'a'=ABC in the listview, the value is put in label5. And when I click on button1, the value ABC is placed in the txtLeak.
Now I select checkbox2, and I select cell 'D' = KEF, the value is put in label 5. And when I click on button1, the valued KEF is placed in txtSidescatter
But this code displays the same value in each checkbox:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form1.CheckBox1.Checked = True Then
Form1.txtLeak.Text = Label5.Text
End If
If Form1.CheckBox2.Checked = True Then
Form1.txtSidescatter.Text = Label5.Text
End If
If Form1.CheckBox3.Checked = True Then
Form1.txtLeakageSideScatter.Text = Label5.Text
End If
If Form1.CheckBox4.Checked = True Then
Form1.txtForwardBackscatter.Text = Label5.Text
End If
If Form1.CheckBox5.Checked = True Then
Form1.txtLeakageForward.Text = Label5.Text
End If
Close()

End Sub

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#10 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Checkboxes display the same values

Posted 15 March 2013 - 01:45 PM

Look, it doesn't do any good to just repeat a previous post, along with the previous code. I've already told you that we need to see the code you use to choose the data. What you are showing me is the code to send the data elsewhere (to TextBoxes).

From the picture you posted, I can see you click the CheckBoxes, and I can see where the data goes in the TextBoxes, but that doesn't do a lot of good, without seeing how you do it.

There are many ways to choose data, and nobody on here will write that code for you. If you post the code you use to choose the data, we stand a good chance of being able to recommend a way to prevent the problem you're having.

Have you even tried any of the suggestions you got?
Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Checkboxes display the same values

Posted 15 March 2013 - 01:47 PM

It really appears to me that you could populate the textboxes from the selecteditem of the listview

If Checkbox2.Checked Then
Form1.txtSidescatter.Text = ListView1.FocusedItem.SubItems(5).Text
End If


Repeat this for the other Checkboxes while changing the SubItems index to the column number you want displayed in that CheckBox's textbox.
Was This Post Helpful? 0
  • +
  • -

#12 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 199
  • View blog
  • Posts: 696
  • Joined: 01-February 13

Re: Checkboxes display the same values

Posted 15 March 2013 - 02:20 PM

Hello koppong,
If you have both checkboxes on the other form checked at the same time and it runs threw the code you have shown it is going to set every one of the textboxes that have the checkboxes checked to label5`s text. If you only have one checkbox at a time checked it will work as you want. I would use RadioButtons so when you select one it will unselect the others. That way you do not set more than one textbox at a time. Otherwise you are going to have to set the code you posted up so it will see if each textbox on the other form has been filled already and only set the one that is empty to label5 text.

ChrlieMay - That would be SubItem(4) wouldn`t it

This post has been edited by IronRazer: 15 March 2013 - 02:26 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1