Is it possible to bind the first element in a collection in a datagrid?

I have a datagrid and I need to bind a property in the first element of the collection of my datasource object. By the momento I am using a converter:
<DataGridTextColumn Header="MyValue" Binding="{Binding Converter={StaticResource myConverter}}"/>
But I would like to avoid the need to use a converter, so I have tried this:
<DataGridTextColumn Header="MyValue" Binding="{Binding MyCollectionProperty.ElementAt(0).MyValue}"/>
Is there any way to do it?

You cannot call ElementAt(i) from the XAML because it is a method.
MyCollectionProperty[0] will certainly get you the first value of the MyCollectionProperty collection provided that the type has an indexer.
If you want to be able to this without using a converter you must change the type of the property from ICollection<T> to for example IList<T>.
You could create a wrapper property (potentially in a partial class definition) and bind to this one:
//old property:
public ICollection<YourType> MyCollectionProperty {
get;
set;
//new wrapper:
public IList<YourType> MyCollectionPropertyWrapper {
get {
return new List<YourType>(this.MyCollectionProperty);
<DataGridTextColumn Header="MyValue" Binding="{Binding MyCollectionPropertyWrapper[0].MyValue}"/>
ICollections are not very XAML friendly and you cannot bind to the first item of an ICollection using an indexer or ElementAt(0) or any other direct way.
Please remember to mark all helpful posts as answer to close your threads.

Similar Messages

  • Creating XML from XSD, Only create The First Element

    Hi,
    I create a XML File from a xsd schema by this way:
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setNamespaceAware(true);
              factory.setValidating(true);
                   factory.setAttribute(JAXP_SCHEMA_LANGUAGE,W3C_XML_SCHEMA);
                   factory.setAttribute(JAXP_SCHEMA_SOURCE, new File(MY_SCHEMA));   
                    DocumentBuilder documentBuilder =factory.newDocumentBuilder();
              documentBuilder.setErrorHandler(new SimpleDOMHandler());
              Document parse = documentBuilder.parse(new File(MY_XML));The first lines of the schema:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         targetNamespace="http://gencat.net/scsp/esquemes/peticion"
         elementFormDefault="qualified" attributeFormDefault="unqualified"
         id="Peticio" xmlns:p="http://gencat.net/scsp/esquemes/peticion">
         <xs:element name="Apellido1">
              <xs:simpleType>
                   <xs:restriction base="xs:string">
                        <xs:maxLength value="40" />
                   </xs:restriction>
              </xs:simpleType>
         </xs:element>
         <xs:element name="Apellido2">
            .............................The problem is that the created document only have the first element "Apellido1". I dont know if it is a wrong xsd, or i'm using a bad way to do it.
    Thanks a lot, and apologize for my english

    Hi,
    Is it possible to create and populate XML from an XSD
    without knowing what the XSD elements are beforehand
    (all the examples appear to know what the input XSD
    will be, and therefore know what the set and get
    methods should be called)? I think it is possible--you would have to recompile each time (unless you can dynamically recompile, which would be neat), but using the classes getMethod() function, you can list all the methods. You would then have to do some tricky logic to determine which of the getMethods you want (for example NOT getClass()), and you can basically call them in sequence. You also need to worry about handling lists & recursively call xxxType classes.
    I'm experimenting with this, and it can get a little frustrating because there are a lot of odd cases to handle (for example, while setting the elements of a list, you need to actually get the list & add elements to it), but I think it's possible.
    >
    Can a user browse for an xsd to input, and the java
    will dynamically create the get methods, and be able
    to create instances and populate variables before
    converting to XML?
    What I'm puzzled about is where you'd get the data to populate the variables? Perhaps a database, or a bean? If you just want to make a test xml file, then it doesn't matter, but with real data, I think you'd still have to change how you actually get the variables you want to populate the xml file with, right? In other words, if your schema changed, the parameters you're passing to the set methods would change as well.
    Maybe we'll see some more packages in the future to make this task easier.

  • B2B EDI translation ----Is it possible to increase the sub-element length

    B2B EDI translation ----Is it possible to increase the sub-element length??
    Am new to the B2B 10g- EDI Integration environment. In our production setup, am getting the following error.
    B2B EDI Translation failed, because one of the fields was too long. The length of Sub-element length is '41'. The maximum allowed length is '35'.
    In the segment RFF defined in the guideline at position 0070; Is it possible to increase / expand the lenght from 35 to 41.....
    Thanks and Rgds,
    -Srini

    Hi Nitesh
    I have the same problem what srini explained above.
    I'm using Oracle B2B Document editor.
    That corresponding element's field is in disabled state ,a red triangle displays in top right corner of that field.
    Could you help me to solve this issue?
    Regards
    Kathir

  • Sort an an arrayList by the first element of an array

    Hi,
    I am really struggling trying to sort an arratList of arrays. I have an arrayList
    ArrayList<String[]> myArrayList = new ArrayList<String []>(100);
    Within this array I have may arrays with 2 elements
    String[] myArray1 = {"Peter", "London"};
    String[] myArray2 = {"John", "London"};
    String[] myArray3 = {"Tony", "Birmingham"};
    I add all these arrays to the arrayList and want to sort by the first element of the array. Basically I expect the final arrayList to be in the order of:
    "John", "London"
    "Peter", "London"
    "Tony", "London"
    Thanks
    Peter

    Hi,
    I am really struggling trying to sort an arratList of
    arrays. I have an arrayList
    ArrayList<String[]> myArrayList = new
    ArrayList<String []>(100);
    Within this array I have may arrays with 2 elements
    String[] myArray1 = {"Peter", "London"};
    String[] myArray2 = {"John", "London"};
    String[] myArray3 = {"Tony", "Birmingham"};
    I add all these arrays to the arrayList and want to
    sort by the first element of the array. Basically I
    expect the final arrayList to be in the order of:
    "John", "London"
    "Peter", "London"
    "Tony", "London"
    Thanks
    PeterThis can be done by using
    Collections.sort(myArrayList, new Comparator<String[]>() {
    public int compare(String[] s1, String[] s2) {
    if (s1.length() <1) {
    return -1;
    if (s2.length() <1) {
    return 1;
    return s1[0].compareTo(s2[0]);
    });

  • Possible to show the WBS element in the down payment request?

    Hi,
    We have a

    Hi,
    We have a Plant maintenance order with a WBS element.
    We have created a PO for a vendor. The WBS element is not shown on the PO.
    Is it possible to show the WBS element on the down payment request of that vendor?
    Thank you for your feedback.
    Kind regards,
    Linda

  • WebService problem: only the first element of a string array is returned

    Hello,
    i did the J2EE QuickCarRental tutorial and extended it by some features: I created another entity bean and implemented four new methods in the QuickOrderProcessor. Then i deployed it as a WebService and accessed it using the Visual Composer.
    Everything works fine except the return value of one WebService method. I created a method with the return value String[]. But the Visual Composer reads it as String. Only the first element of the resulting string array is displayed. Although the test at the web-page http://<server>:<port>/QuickCarRentalService/Config1 displays the whole string array with all its elements. What did i wrong?
    Another problem is that after deploying the J2EE-Application with new WebService methods the changes are not visible inside the visual composer. Although the test at the web-page http://<server>:<port>/QuickCarRentalService/Config1 displays the changes. Do i have to restart the WebService system in the portal content? If yes how can i do that?

    Here are details about setting up and using web services and some examples:
    /people/prakash.darji/blog/2006/10/10/external-web-service-proxy-configuration-for-visual-composer

  • ArrayList drops the first element

    I hate asking for help, but this has me confused.
    I have a code that outputs the elements of an arraylist as text strings to a file. For some reason, the first element of the ArrayList gets dropped, but every other element after gets saved to text perfectly.
    public void writeOut(ArrayList a)throws IOException{
        String[] out=new  String[a.size()];
        for(int i=0;i<out.length;i++){
            out=a.get(i).toString();
    System.out.println("" + out[i]); //test line to see if element has been moved
    I have also tried:
    public void writeOut(ArrayList a)throws IOException{
        String[] out=new  String[a.size()];
        for(int i=0;i<out.length;i++){
            out=(String)a.get(i);
    System.out.println("" + out[i]); //test line to see if element has been moved
    The code is straight forward, the best I can tell...so what am I overlooking? I am assuming that my array needs to be primed or something first. I suppose I could make the array one bigger and put some bogus value in the first element...That doesn't really seem the right way to do it though.

    I didn't notice it either until I tried to pass it an ArrayList with only one string....I must be having a problem where the ArrayList is being created then.
    And that is exactly where the problem was... :sigh:
    Thanks for checking that for me.

  • Retrieve first element of a Collection

    Hello,
    How to retrieve only the first element (class) of a Collection?
    Thank you
    Sylvain

    Object firstElement = yourCollection.iterator().next()

  • How to delete the last element of a collection without iterating it?

    how to delete the last element of a collection without iterating it?

    To add to jverd's reply, even if you could determine the last element, in some collections it is not guaranteed to always be the same.
    From HashSet:
    It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.

  • Is it possible to bind the elments with context node dynamically?

    Hi All,
    Is it possible to dynamically bind elements with context nodes?
    In other words, at runtime, can we change the binding of an Inputfield to another context. Or a table to programmatically bind to another table?
    Regards,
    urbashi

    hi urbashi.......
          it is possible..
           you should first pass the id of he ui element and then bind it.
           for ex:
             if there is an input field, you can get the attribute that is bound, using cl_wd_input_field->bound_value.
             if you want to set an attribute, use cl_wd_input_field->bind_value.
             the first one will give an idea of how a valueshould be given.
    ---regards,
       alex b justin

  • Is it possible to change the first page of a web application that was built using the UI?

    Hello Community
        Using Sharepoint 2010 Server and the UI I built and application and would like
    to continue building the web application using the UI.
        The application's first page was built using a Blank Site template and
    the subsequent subsites were built using the Team Site template.
        In retrospect the first page should also have been built using a Team Site template.
        It may be unnecessary to make to delete the application
    and create the first page as a Team Site and then have to create all of the
    subsites (Team Sites) all over again.
        As a solution to prevent deleting the whole application and creating application
    with all of the subsites all over again whether it is possible to do any of the
    following:
        - Convert the Blank Site page into a Team Site page which would allow
    me to leave all of the subsites as is.
        - rename the Blank site page which would in effect would be renaming the application
    then create a new Team Site page which would be essentially creating a new application and
    then adding all of the subsites contained in the renamed application that has the first page
    as a Blank page.
        And if is possible to add, copy or move the subsites from existing sites to a new Team Site
    page, how do you add, copy or move the subsites from one application to a diffent application?
        Thank you
        Shabeaut

    Hi Shabeaut,
    According to your description, my understanding is that you want to change the template of the root site without creating the susites in another web application.
    I recommend to export all the existing subsites and import them to new web application.
    More references:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/cc7c11ec-e4da-4ddb-babd-db76ccb35664/move-subsite-to-new-site-collection?forum=sharepointadminprevious
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/fd321bac-16a7-47e4-842e-00b7ca0f7f05/move-subsite-to-other-site-collection-as-subsite?forum=sharepointadminprevious
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Message Mapping: Map value from the first element in a context in target el

    Hi experts,
    I have a problem with a message mapping in XI. I hope you can help me. At first I will give you a source and a target structure. Then I will explain the problem.
    <u>Source structure:</u>
    <E1EDP01>
       <E1EDPT1>
          <TDID> ... </TDID>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
       </E1EDPT1>
    </E1EDP01>
    The structure can contain more than one E1EDP01-Elements, more than one E1EDPT1-Elements and more than one E1EDPT2-Elements.
    <u>target structure:</u>
    <LineItem>
       <vendmemo> ... </vendmemo>
    </LineItem>
    For every E1EDP01-Element my mapping creates one LineItem-Element in the target structure. To fill the element <vendmemo> the mapping should do the following steps:
    The mapping should search in E1EDP01 for a E1EDPT1 with the TDID = Z505. And from this E1EDPT1-Element (with the TDID=Z505) the mapping should take the value <TDLINE> from the first E1EDPT2-Element in the context of the E1EDPT1-Element (the E1EDPT1 with the TDID=Z505) and put this value in <vendmemo>.
    The mapping should do this action for every E1EDP01 -> so for every LineItem.
    I tried it with UDF but I didn't found a solution. Can anybody help me?
    best regards
    Christopher

    Hello experts,
    i was wrong ... my mapping isn't still working. I had created a test instance. and only for this test instance the mapping (see above) works.
    Can anybody help me? I'm trying the whole day but I can't find a solution. Here a second description of my problem:
    <u>Source Structure:</u>
    <E1EDP01>
       <E1EDPT1>
          <TDID> ... </TDID>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
       </E1EDPT1>
    </E1EDP01>
    <E1EDP01>
       <E1EDPT1>
          <TDID> ... </TDID>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
          <E1EDPT2>
             <TDLINE> ... </TDLINE>
          </E1EDPT2>
       </E1EDPT1>
    </E1EDP01>
    <u>Target Structure:</u>
    <LineItem>
       <vendmemo> ... </vendmemo>
    </LineItem>
    <LineItem>
       <vendmemo> ... </vendmemo>
    </LineItem>
    <u>Description of my Problem:</u>
    For each E1EDP01 in the source structure the mapping creates one LineItem in the target structure.
    The element "vendmemo" should be created in any case ... also if it will be empty.
    To fill the element "vendmemo" the mapping should search in E1EDP01 for a E1EDPT1 with the TDID=Z505. If there is an element E1EDPT1 with the TDID=Z505, the mapping should write the TDLINE from the first E1EDPT2 (under the element E1EDPT1 with the TDID=Z505) in the target field "vendmemo".
    The Problem is that TDLINE an TDID are not in the same context. I tried it with setting the context of both to E1EDP01. But it was not working ... have you any idea oder suggestion?
    Thank you very much
    best regards
    Christopher

  • Is it possible to add the UI element to iview at runtime?

    Hi Expert,
    I want to do a prototype, which can dynamicly create the UI element(For example, create a new input box) in the form iview, is it possible in VC? as I know in webdynpro it works but I am not sure whether it is allowed in VC.
    Thanks for your answer.

    Hi,
    In whatever scenario you want to create a dynamic UI element in a VC iView, you have to have an event, on occurance of which something happens dynamically. This event can be in the form of a button click or some value coming from a previous iView or page. But the important thing to note is that if you want something to become visible or invisble in your iView, the event to make this happen, has to occur in some other view.
    For example, you can have two forms in an iView, make a button in one form, which when clicked passes something (say a number) to the second form. You can now make your input box or anything else in the second form. In the properties of this second form, you have the <b>visibility</b> field, where you can enter a formula, something like:
    <b>BOOL(IF((@Status==1),true,false))</b>
    Similarly you can make tabs in your iview, make the button in one tab, and do something dynamically in the next tab.
    Reward points if it helps...

  • Is it possible to "indent" the first tab of a JTabbedPane ?

    Hello,
    Is there a simple way to add extra space before the first tab button in a JTabbedPane ? Is it possible to add components into this left area, like the "Favorites" buttons ins IE 7 ?
    Thank you in advance,

    I would imagine that the layout of the tabs is decided by the UI class specific to the platform you are using (i.e. a subclass of javax.swing.plaf.TabbedPaneUI). It would be very complicated, but you could change the layout by creating your own UI class and setting it using tabbedPane.setUI(new MyTabbedPaneUI());

  • BindAggregation only returning the first element from a XML node

    hello everyone,
    investigating on this issue since fiew hours, I need your help (did not find a similar issue).
    here is an xml sample:
    <users>
         <user active="true">
              <reference/>
              <name>
                   <prefix/>
                   <first>first</first>
                   <middle/>
                   <last>last</last>
              </name>
              <location></location>
              <identifier>
                   <domain>mydomain</domain>
                   <login>flast</login>
              </identifier>
              <email>
                   <address>[email protected]</address>
                   <type>text</type>
              </email>
              <roles>
                   <role name="A"/>
                   <role name="B"/>
                   <role name="C"/>
                   <role name="D"/>
                   <role name="E"/>
                   <role name="F"/>
                   <role name="G"/>
              </roles>
              <groups>
                   <group name="A1"/>
                   <group name="A2"/>
              </groups>
         </user>
    </users>
    After having set the data in the table:
    oModel.setData(data);               
    oTable.setModel(oModel);
    oTable.bindRows("/user");
    I am able to bind correctly properties like first name & last name in my table... but I am not able to do a bindAggregate on roles !
    When I do this, only the first role is returned everytime for each row.
    With the example above,
    It displays, : first as firstname, last as lastname, & only role A instead of displaying all roles from A to G as above in the xml.
    Here is the bindAggregation:
    oTable.addColumn( new sap.ui.table.Column({
         label: new sap.ui.commons.Label({text: "Roles"}),
         template: new sap.ui.commons.ListBox({  
              "items": {     
                   path: "roles",
                   template: new sap.ui.core.ListItem({text: "{role/@name}",})
    Where is my misunderstanding/mistake ? or how should I deal for having all roles displayed correctly in the listbox of this column ?
    No proposal ?
    Files (javascript & data) for reproducing this behavior are attached below,
    Really thank's in advance to each of you for your coming help,
    Best Regards

    hello everyone,
    investigating on this issue since fiew hours, I need your help (did not find a similar issue).
    here is an xml sample:
    <users>
         <user active="true">
              <reference/>
              <name>
                   <prefix/>
                   <first>first</first>
                   <middle/>
                   <last>last</last>
              </name>
              <location></location>
              <identifier>
                   <domain>mydomain</domain>
                   <login>flast</login>
              </identifier>
              <email>
                   <address>[email protected]</address>
                   <type>text</type>
              </email>
              <roles>
                   <role name="A"/>
                   <role name="B"/>
                   <role name="C"/>
                   <role name="D"/>
                   <role name="E"/>
                   <role name="F"/>
                   <role name="G"/>
              </roles>
              <groups>
                   <group name="A1"/>
                   <group name="A2"/>
              </groups>
         </user>
    </users>
    After having set the data in the table:
    oModel.setData(data);               
    oTable.setModel(oModel);
    oTable.bindRows("/user");
    I am able to bind correctly properties like first name & last name in my table... but I am not able to do a bindAggregate on roles !
    When I do this, only the first role is returned everytime for each row.
    With the example above,
    It displays, : first as firstname, last as lastname, & only role A instead of displaying all roles from A to G as above in the xml.
    Here is the bindAggregation:
    oTable.addColumn( new sap.ui.table.Column({
         label: new sap.ui.commons.Label({text: "Roles"}),
         template: new sap.ui.commons.ListBox({  
              "items": {     
                   path: "roles",
                   template: new sap.ui.core.ListItem({text: "{role/@name}",})
    Where is my misunderstanding/mistake ? or how should I deal for having all roles displayed correctly in the listbox of this column ?
    No proposal ?
    Files (javascript & data) for reproducing this behavior are attached below,
    Really thank's in advance to each of you for your coming help,
    Best Regards

Maybe you are looking for

  • New PC - have library on external hard drive -won't sync with my ipod

    I have itunes library set up and recognizing my itunes library, but won't let me synce with my ipod. I went through the aurhtorization stuff, Any body know what I'm missing Thanks

  • Permissions bug, according to ISP engineer.

    I am having problems setting up VPN for Windows 8.1 Pro 64-bit, home workstation computer, not networked. I am also having general non-specific problems with Internet connectivity, according to network engineers.  I having a WiFi Mac and a hard-wired

  • Is it safe to download Adobe flash player on Macbook Pro?

    I can't watch any Youtube video's at all. It's telling me to downlaod the flash player. I just wanna make sure before I do, that its safe too do so? When I download it will it mess something with my warenty or no? Thanks in advance!

  • Is there a Motion "How To?"

    I'm new to motion, so is there a how to guide/tutorial around that shows kind of how to get started and some cool tricks? (other than the demo)

  • Need Help in Printing

    Hey everyone; Im developing a Swing desktop application. it contains a kind of application form (JLabels, JTextFields, JCheckBox,..). I need to add a print application option. Both the labels and the user input should be printed. I have a problem wit