Solved

Update by either checkbox or textbox

Posted on 2011-09-05
11
255 Views
Last Modified: 2012-05-12
Greetings again mates.

I have been searching for answers to this one for awhile and I am still struggling.

I have 2 sections, Section 1 and Section 2.

Section one has 5 textboxes, textbox1...textbox5 and 5 checkboxes, checkbox1 through checkbox5.

Then section2 has 5 textboxes, checkAmount1 through checkAmount5.

The way it is supposed to work is that if you enter a number into any of the textobexes, say textbox1 for instance, and you check checkbox1, then the same number you enter into textbox is automatically entered into checKAmount1, textbox2, into checkAmount2, etc.

Here is where the issue comes in.

If you check checkbox1 FIRST FIRST and then enter a number into textbox1, everything works fine as expected.

If,however, you enter a number into textbox1 FIRST before checking a box, then nothing gets entered into the corresponding checkAmount.

I have struggled with this but no luck so far.

How do I tweak this code to make it happen?

Please let me know if you need an additional info.

        If chckamttext.Text <> "0" Then
            Select Case chckded
                Case "chck1"
                    If chckBox1.Checked AndAlso chck1.Text.Trim() <> [String].Empty Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname1.Text
                    End If
                Case "chck2"
                    If chckBox2.Checked AndAlso chck2.Text.Trim() <> [String].Empty Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname2.Text
                    End If

                Case "chck3"
                    If chckBox3.Checked AndAlso chck3.Text.Trim() <> [String].Empty Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname3.Text
                    End If

                Case "chck4"
                    If chckBox4.Checked AndAlso chck4.Text.Trim() <> [String].Empty Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname4.Text
                    End If

                Case "chck5"
                    If chckBox5.Checked AndAlso chck5.Text.Trim() <> [String].Empty Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname5.Text
                    End If
            End Select
        ElseIf chckamttext.Text = "0" And chckded <> "" Then
            chckamtbot.Text = "0"
            chckfed.Text = ""
        End If

Open in new window


Thanks
0
Comment
Question by:sammySeltzer
  • 6
  • 4
11 Comments
 
LVL 9

Expert Comment

by:sarabhai
ID: 36485266
where u write the code.
code need to be write/execute after checkbox click and textbox change value.
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 36486433
I'm afraid I did not fully understand the problem but... I'll try :)

To solve your task you need some event handlers for checkboxes.CheckedChanged event.

See my code below
Private Sub CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
        CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged

        Select Case DirectCast(sender, CheckBox).Name
            Case "CheckBox1"
                setControlsValues_1()
            Case "CheckBox2"
                setControlsValues_2()
            Case "CheckBox3"
                setControlsValues_3()

        End Select
    End Sub

    Private Sub setControlsValues_1()
        If Not String.IsNullOrEmpty(TextBox1.Text) AndAlso CheckBox1.Checked Then
            Me.chckamtbot1.Text = TextBox1.Text
        Else
            '?????
        End If
    End Sub
    Private Sub setControlsValues_2()
        If Not String.IsNullOrEmpty(TextBox2.Text) AndAlso CheckBox2.Checked Then
            Me.chckamtbot2.Text = TextBox2.Text
        Else
            '?????
        End If
    End Sub
    Private Sub setControlsValues_3()
        If Not String.IsNullOrEmpty(TextBox3.Text) AndAlso CheckBox3.Checked Then
            Me.chckamtbot3.Text = TextBox3.Text
        Else
            '?????
        End If
    End Sub

Open in new window

0
 
LVL 28

Author Comment

by:sammySeltzer
ID: 36488419
anarki_jimbel,

Thankyou very much for your efforts and your response.

But what is it that you don't understand?

I will be more than glad to try to explain again.

I have 2 sections, Section1 and Section2.

On Section1, I have 5 textboxes and 5 checkboxes.

Let's call the textboxes, textbox1, textbox2, textbox3, textbox4, textbox5.

Then 5 checkboxes, checkbox1, checkbox2, checkbox3, checkbox4, checkbox5.

Then on Section2, we have another 5 textboxes - checkAmount1, checkAmount2, checkAmount3, checkAmount4, checkAmount5.

The way it is *supposed* to work is you enter a number into a textbox and then check the appropriate checkbox in Section1, then that amount goes in the corresponding textbox in Section2.

For instance, let's say we enter 2 box in textbox1 and check checkbox1 in Section1, that number - 2, will automatically be populated into CheckAmount1 in Section1.

So, whether you check a box FIRST before entering a number, or you enter a number FIRST before checking a box, as long as a number is entered into a textbox and the associated checkbox is checked as described above, that number should be automatically populated into the corresponding checkAmount in Section2.

If you enter a number but don't check a checkbox, that number should NOT be populated into the corresponding checkAmount in Section2

The way it is working so far is you MUST check a checkbox FIRST before entering a number.

If you do that, then that number goes into the corresponding CheckAmount in Section2.

We want it to work whether you check a checkbox first or you enter a number firs as long as a number is entered and the associated checkbox is checked, then that amount shouold go to the corresponding checkAmount in section2.

I hope this is clearer.

Again, thanks for your assistance.

I thought the code I posted above would do the trick but this one got me so stumped.
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 36492086
OK, try this code. For simplicity I have only 3 controls of each type :)

I tested and believe that is what you want
Public Class Form1

    Private Sub CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
                CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, _
                TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged

        Select Case DirectCast(sender, Control).Name
            Case "CheckBox1", "TextBox1"
                setControlsValues_1()
            Case "CheckBox2", "TextBox2"
                setControlsValues_2()
            Case "CheckBox3", "TextBox3"
                setControlsValues_3()
        End Select
    End Sub

    Private Sub setControlsValues_1()
        If Not String.IsNullOrEmpty(TextBox1.Text) AndAlso CheckBox1.Checked Then
            Me.CheckAmount1.Text = TextBox1.Text
        Else
            '?????
        End If
    End Sub
    Private Sub setControlsValues_2()
        If Not String.IsNullOrEmpty(TextBox2.Text) AndAlso CheckBox2.Checked Then
            Me.CheckAmount2.Text = TextBox2.Text
        Else
            '?????
        End If
    End Sub
    Private Sub setControlsValues_3()
        If Not String.IsNullOrEmpty(TextBox3.Text) AndAlso CheckBox3.Checked Then
            Me.CheckAmount3.Text = TextBox3.Text
        Else
            '?????
        End If
    End Sub
End Class

Open in new window

0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 36492100
Probably Private Sub CheckedChanged not the best name. May be call it like ControlStateChanged or something else. Does not really matter :)
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 28

Author Comment

by:sammySeltzer
ID: 36492932
Please help me understand; what is the difference between your code and mine?
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 36493324
OK, I didn't see your whole code :)

The main trick in my code is that the event handler handles BOTH text box and check box changes:

=====================================
 Sub CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _

                CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, _

                TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
=====================================

So, does not matter if you change text in a text box or check-uncheck checkbox - the system checks checkbox state and if allowed copies textbox content.

That's all!
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 36493330
Ask questions if not clear.
Unfortunately, it looks, we have some time shift. I live on Pacific time :)
0
 
LVL 28

Author Comment

by:sammySeltzer
ID: 36497553
thanks a lot.

However, I am sure there is more to this code.

I am running into many errors, like:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types

or

'Name' is not a member of system.web.ui.control
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 36499121
OK, disregard my code. I missed it is ASP. The code is for forms...
My apologies
0
 
LVL 28

Author Closing Comment

by:sammySeltzer
ID: 36519660
It didn't solve my problem. but credit for efforts.

Thank you
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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

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

22 Experts available now in Live!

Get 1:1 Help Now