Binding XML to 2 combo boxes 
Author Message
 Binding XML to 2 combo boxes

Consider the following XML:

<AreaCodes>
        <Area Code="212">
                <Prefix>123</Prefix>
                <Prefix>234</Prefix>
                <Prefix>345</Prefix>
        </Area>
        <Area Code="214">
                <Prefix>456</Prefix>
                <Prefix>567</Prefix>
                <Prefix>678</Prefix>
        </Area>

        .
        .Many more area codes here
        .

</AreaCodes>

I want to have 2 simple combo boxes displayed side by side.  The first
combo should be bound to the XML to the Area Code item.  When a
particular code is selected in the combo, the second combo box should be
filled with the prefixes that correspond to the selected area code in the
first combo.

For example, if I select 212 in the first combo, I want the prefixes
associated with 212  (123,234, and 345) to be displayed in the second
combo box.

In addition, if the user types a value into the first combo, that value
should be added to the XML and any entries typed into to second combo
should be added as prefixes appropriately.

I created a simple XML Schema and added it to the project that models
this data, but I'm not sure if that is the correct approach or if it will
even work.

Should I use a data set?

Any pointers would be appreciated.

Chris Dunaway

--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail



Wed, 20 Jul 2005 05:51:55 GMT  
 Binding XML to 2 combo boxes
Here's the problem as I see it.  You've combined an attribute node with,
essentially an element node format.

So, what your going to need is a routine under the combo box which reads the
node's attribute, clears the second combo box and then populates it with the
appropriate child nodes.

Here's an example of what is meant:

Dim Nodelist as object
Set nodelist = xmldoc.GetElementsByTagName("Area")
For x = 0 To Nodelist.length-1
    If Nodelist(x).Attributes(0).Text = ComboBox1.Text Then
        Combobox2.clear
         For y = 0 To Nodelist(x).Children -1
                        Combobox2.items.add(Nodelist(x).childnodes(y).Text
         Next y
    Exit For
End If
Next x

I know this isn't exactly dotnetish, but it should help you understand whats
needed to get the job done.

hth

r.t.edwards
http://www.pwpsquared.net


Quote:
> Consider the following XML:

> <AreaCodes>
>     <Area Code="212">
>         <Prefix>123</Prefix>
>         <Prefix>234</Prefix>
>         <Prefix>345</Prefix>
>     </Area>
>     <Area Code="214">
>         <Prefix>456</Prefix>
>         <Prefix>567</Prefix>
>         <Prefix>678</Prefix>
>     </Area>

>     .
>     .Many more area codes here
>     .

> </AreaCodes>

> I want to have 2 simple combo boxes displayed side by side.  The first
> combo should be bound to the XML to the Area Code item.  When a
> particular code is selected in the combo, the second combo box should be
> filled with the prefixes that correspond to the selected area code in the
> first combo.

> For example, if I select 212 in the first combo, I want the prefixes
> associated with 212  (123,234, and 345) to be displayed in the second
> combo box.

> In addition, if the user types a value into the first combo, that value
> should be added to the XML and any entries typed into to second combo
> should be added as prefixes appropriately.

> I created a simple XML Schema and added it to the project that models
> this data, but I'm not sure if that is the correct approach or if it will
> even work.

> Should I use a data set?

> Any pointers would be appreciated.

> Chris Dunaway

> --
> If you don't like lunchmeat, please remove it from my e-mail address to
> send me an e-mail



Thu, 21 Jul 2005 03:36:03 GMT  
 Binding XML to 2 combo boxes


Quote:
> Here's the problem as I see it.  You've combined an attribute node
> with, essentially an element node format.

I can be flexible with the xml.  Would the following be more appropriate?  
And would that affect the code you posted?

<AreaCodes>
        <212>
                <Prefix>123</Prefix>
                <Prefix>234</Prefix>
                <Prefix>345</Prefix>
        </212>
        <214>
                <Prefix>456</Prefix>
                <Prefix>567</Prefix>
                <Prefix>678</Prefix>
        <214>

        .
        .Many more area codes here
        .

</AreaCodes>

--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail



Sat, 23 Jul 2005 04:52:37 GMT  
 Binding XML to 2 combo boxes
Much better. Should be working like a champ now.


Quote:


> > Here's the problem as I see it.  You've combined an attribute node
> > with, essentially an element node format.

> I can be flexible with the xml.  Would the following be more appropriate?
> And would that affect the code you posted?

> <AreaCodes>
>     <212>
>         <Prefix>123</Prefix>
>         <Prefix>234</Prefix>
>         <Prefix>345</Prefix>
>     </212>
>     <214>
>         <Prefix>456</Prefix>
>         <Prefix>567</Prefix>
>         <Prefix>678</Prefix>
>     <214>

>     .
>     .Many more area codes here
>     .

> </AreaCodes>

> --
> If you don't like lunchmeat, please remove it from my e-mail address to
> send me an e-mail



Wed, 27 Jul 2005 06:22:08 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. binding XML to Combo Box

2. Combo Box like Data Bound Combo Box?

3. Data Bound Combo Box within a Data Bound Grid

4. Bound combo box and text box

5. HELP! ADO bound list box and combo box

6. Data bound Combos or Not Data Bound Combos

7. Read XML elements into Combo Box

8. Iterating through XML to add to combo box?

9. Read XML elements into a Combo Box

10. Read XML elements into Combo Box

11. combo box bound column problem

12. Bound combo box won't let be cancel/undo, continually generating error messages

 

 
Powered by phpBB® Forum Software