Solved

Help with setting values when clicking on checkboxex of a combobox control

Posted on 2012-03-09
10
340 Views
Last Modified: 2012-03-30
Hello,

When I click on several checkboxes to set a variables xx,yy,zz,ww to 1 for rows checked my code below (Msgbox ("Test") never executes, any ideas what is causing this problem?

Code:

  Protected Sub Button131_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button131.Click

        Dim str1 As String = Nothing
        xx = 0
        yy = 0
        zz = 0
        ww = 0
        Dim ctrlA As Control = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
                MsgBox("Test") *****Does not execute
                If i = 0 Then
                    xx = 1
                End If
                If i = 1 Then
                    yy = 1
                End If
                If i = 2 Then
                    zz = 1
                End If
                If i = 3 Then
                    ww = 1
                End If
            End If
            MsgBox(i)
        Next
        MsgBox(xx)
        MsgBox(yy)
        MsgBox(zz)
        MsgBox(ww)
End Sub

Control:

<cc1:C1ComboBox ID="C1SDeactivation" runat="server"
                         OpenDropDownOnLoad="True"
                         SelectionMode="Multiple" Width="180px"    
                         onselectedindexchanged="C1SDeactivationA_SelectedIndexChanged"
                         OnClientSelectedIndexChanged ="C1SDeactivationA_OnClientSelectedIndexChanged"
                         AccessKey="" ToolTip="" HideDropDownListOnBlur="False"
                         DropDownPositioningMode="BottomCenter" DropDownHeight="100"
                         Text="Select (Multiple Allowed)" ShowTrigger="False" IsEditable="False">
                          <ItemsTemplate>
                            <asp:CheckBox ID="SDeactivation" runat="server" onChange="setColor(); " />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>
                     </cc1:C1ComboBox>


Thanks,

Victor
0
Comment
Question by:vcharles
  • 5
  • 3
  • 2
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37703442
Its because the following condition

 If C1SDeactivation.Items(i).Selected Then

never evaluates to true.
0
 

Author Comment

by:vcharles
ID: 37703461
I know but I don't know why because I did select the rows when I clicked on the checkboxes.
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37703652
I may be wrong, but I think the checkbox property you are looking for is Checked not Selected ( you my need to cast the control to checkbox to access this)
0
 

Author Comment

by:vcharles
ID: 37703676
I'm afraid checked is not a propery of the combobox, how do I cast the control tyo checkbox?
Thanks.
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37703776
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:vcharles
ID: 37705494
Hi Unfortunately,

I still can't figure out why the code I initially posted doesn't work now, it thought worked a few weeks ago, can you please take a closer look at the syntax to see why
 "If C1SDeactivation.Items(i).Selected then" is not executing even when I select the rows.

I think the problem might be because the ID of my checkbox is SDeactivation as shown below:

  <ItemsTemplate>
                            <asp:CheckBox ID="SDeactivation" runat="server" onChange="setColor(); " />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>:

and my code is looking for the control with ID SDeactivation for the combobox. How do I ensure It is looking for data checked from the checkbox?

Code:


 Protected Sub Button131_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button131.Click

        Dim str1 As String = Nothing
        xx = 0
        yy = 0
        zz = 0
        ww = 0
        Dim ctrlA As Control = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
                MsgBox("Test") *****Does not execute
                If i = 0 Then
                    xx = 1
                End If
                If i = 1 Then
                    yy = 1
                End If
                If i = 2 Then
                    zz = 1
                End If
                If i = 3 Then
                    ww = 1
                End If
            End If
            MsgBox(i)
        Next
        MsgBox(xx)
        MsgBox(yy)
        MsgBox(zz)
        MsgBox(ww)
End Sub

Control:

<cc1:C1ComboBox ID="C1SDeactivation" runat="server"
                         OpenDropDownOnLoad="True"
                         SelectionMode="Multiple" Width="180px"    
                         onselectedindexchanged="C1SDeactivationA_SelectedIndexChanged"
                         OnClientSelectedIndexChanged ="C1SDeactivationA_OnClientSelectedIndexChanged"
                         AccessKey="" ToolTip="" HideDropDownListOnBlur="False"
                         DropDownPositioningMode="BottomCenter" DropDownHeight="100"
                         Text="Select (Multiple Allowed)" ShowTrigger="False" IsEditable="False">
                          <ItemsTemplate>
                            <asp:CheckBox ID="SDeactivation" runat="server" onChange="setColor(); " />
                             <%# DataBinder.Eval(Container.DataItem, "SDeactivation")%>
                         </ItemsTemplate>
                     </cc1:C1ComboBox>


Thanks,


Victor
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37705942
Have you stepped through the code? You have

Dim ctrlA As Control = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then

you are finding ctrlA but using name of the control

Try

Dim ctrlA As C1Combobox = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
0
 

Author Comment

by:vcharles
ID: 37705994
Hello,

I tried it but  "If C1SDeactivation.Items(i).Selected Then" still doesn't execute when I select the rows. Not certtain why use ctrlA since it is not used anywhere in the code, could that be the problem?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37706973
Yes that is the problem. I should have updated the rest of the code. So either

Dim ctrlA As C1Combobox = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To ctrlA.Items.Count - 1
            If ctrlA.Items(i).Selected Then

pr

Dim C1SDeactivation As C1Combobox = MultiView1.FindControl("C1SDeactivation")
        For i = 0 To C1SDeactivation.Items.Count - 1
            If C1SDeactivation.Items(i).Selected Then
0
 

Author Comment

by:vcharles
ID: 37707227
I'm afraid both approaches did not work, looking at an old project where it worked before but still can't figure it out will keep trying a get back to you. Thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

18 Experts available now in Live!

Get 1:1 Help Now