ListView + MVVM: How do I get the value of a selected cell?

Hi,
I love programming WPF using MVVM, but sometimes easy looking problems lead to unbearable suffering.
Here is my problem: I have a simple list view with about a couple of columns. All I want to do is to copy the cell content to clipboard, when the user right-clicks on a cell.
<ListView Grid.Row="0" ItemsSource="{Binding Articles}" SelectedItem="{Binding SelectedArticle}" SelectionMode="Single">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="ID" Width="70" DisplayMemberBinding="{Binding Path=ID, Mode=OneWay}" />
<GridViewColumn Header="Name" Width="150" DisplayMemberBinding="{Binding Path=Name, Mode=OneWay}"/>
<GridViewColumn Header="Price" Width="100" DisplayMemberBinding="{Binding Path=Price, Mode=OneWay}"/>
<GridViewColumn Header="Description" Width="70" DisplayMemberBinding="{Binding Path=Description, Mode=OneWay}"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Without MVVM I probably would have used the some Click-Event and extract the info from the event args. But of course I don't want to break the MVVM pattern.
But if I use some kind of event binding I cannot find a way to retrieve event args or the sender object:
<i:EventTrigger EventName="PreviewMouseRightButtonDown">
<i:InvokeCommandAction Command="{Binding CopyCellValueToClipCommand}"/>
</i:EventTrigger>
Using this trigger I can react to the desired event, but how can I retrieve the cell value?
I really hope you guys have a clue.
Thanks for your help,
Michael

I'm not so sure about listview, I rarely use them for more complicated requirements.
I would use a datagrid.
You can bind a cellinfo:
http://stackoverflow.com/questions/20080130/how-to-bind-currentcell-in-wpf-datagrid-using-mvvm-pattern
<DataGrid AutoGenerateColumns="True"
SelectionUnit="Cell"
SelectionMode="Single"
Height="250" Width="525"
ItemsSource="{Binding Results}"
CurrentCell="{Binding CellInfo, Mode=OneWayToSource}"/>
and
private DataGridCellInfo _cellInfo;
public DataGridCellInfo CellInfo
get { return _cellInfo; }
set
_cellInfo = value;
OnPropertyChanged("CellInfo");
MessageBox.Show(string.Format("Column: {0}",
_cellInfo.Column.DisplayIndex != null ? _cellInfo.Column.DisplayIndex.ToString() : "Index out of range!"));
You can use index and bind selecteditem or get contents of cell:
public DataGridCell GetDataGridCell(DataGridCellInfo cellInfo)
var cellContent = cellInfo.Column.GetCellContent(cellInfo.Item);
if (cellContent != null)
return (DataGridCell) cellContent.Parent;
return null;
Hope that helps.
Recent Technet articles:
Property List Editing ;  
Dynamic XAML

Similar Messages

  • How do you get the value of a selected list item?

    I have a drop-down list that the user can choose from. How do I get the value of what they selected? I thought I could do this by using the NAME_IN function, but I'm getting FRM-40105 Unable to resolve reference to item X. I don't know what I'm doing wrong.
    Thanks!

    Hi,
    You can use an WHEN-LIST-CHANGED trigger, attached to the list-item itself. And, in this trigger, you can use the name of the item to refer its value.
    For example:
    :block_name.list_item_name
    John

  • A problem to get the value of a selected cell

    Hi all,
    I am trying to get the value of a cell in JTable. The problem that I have is ListSelectionListener only listens if the selection changes(valueChanged method).
    It means that if I select apple then rum, only rowSelectionModel is triggered, which means I do not get the index of the column from selectionModel of ColumnModel.
    apple orange plum
    rum sky blue
    This is a piece of code from JTable tutorial that I modified by adding
    selRow and selCol variables to keep track of the location so that I can get the value of the selected cell.
    Thank you.
    if (ALLOW_ROW_SELECTION) { // true by default
    ListSelectionModel rowSM = table.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    System.out.println("No rows are selected.");
    } else {
    int selectedRow = lsm.getMinSelectionIndex();
    selRow = selectedRow;
    System.out.println("Row " + selectedRow + " is now selected.");
    else {
    table.setRowSelectionAllowed(false);
    if (ALLOW_COLUMN_SELECTION) { // false by default
    if (ALLOW_ROW_SELECTION) {
    table.setCellSelectionEnabled(true);
    table.setColumnSelectionAllowed(true);
    ListSelectionModel colSM = table.getColumnModel().getSelectionModel();
    colSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    System.out.println("No columns are selected.");
    } else {
    int selectedCol = lsm.getMinSelectionIndex();
    selCol = selectedCol;
    System.out.println("Column " + selCol + " is now selected.");
    System.out.println("Row " + selRow + " is now selected.");
    javax.swing.table.TableModel model = table.getModel();
    // I get the value here
    System.out.println("Value: "+model.getValueAt(selRow,selCol));
    }

    maybe you can try with :
    table.getSelectedColumn()
    table.getSelectedRow()
    :)

  • How do I get the values from a selected row.

    I am using JDeveloper 9.0.5. On my page, I have placed a button within a table. The button has been assigned an event. The event is within my Action class. This class implements DataAction and has overriden the
    processComponentEvents(DataActionContext actionContext);
    method.
    Question: While I am within the processComponentEvents method, is it possible to obtain the values of selected row?

    Good Morning Jeffery,
    First off thanks for your clear explanation. I have a few related questions as noted from your response:
    There are two ways to communicate the desired model row between the UIX view and the struts controller. One way is to use the singleSelection component in your table and put your buttons in the singleSelection's contents.
    When the user selects the radio button for a particular row and then clicks on one the buttons, a built in event handler in UIX will set the current row in the model to be the user selected row. Therefore, your Struts action can operate on the currently selected model row.
    When you drop a UIX table from the data control palette it is automatically set up in this way (with a single selection).
    Ok, Lets say that i've set everything up as you described. Not lets say that the button was pressed and I hit the overriddenprotected void processComponentEvents(DataActionContext actionContext) throws IOException, ServletException ;
    When I look at the request object, I do not see the values. How do I get access to the rowkey at this point?
    Some people, however, want to actually render buttons in their table rows, and have those buttons initiate an action on their row. If you are doing this, then you need to pass the row id to your struts action as a parameter, which means that you need to know the row id when you are rendering a button for a given row. There is an EL expression that will return the row-id for the current row, it is:
    ${uix.current.rowKeyStr}
    which is not so obvious or well documented in the preview release (sorry) but should be for the production release.
    A generic code snippet would go a long way to shedding some light on that. I guess I am use to using JDeveloper 9.0.3. It seems,"to me", that JDev 9.0.5 has put a completely new twist on things. I find myself wondering when I can use the 9.0.3 syntax and when
    should not. If your team has any short source toys around which demonstrated using rowkeys, or accessing the internal parts of the
    struts controller, I would find that invaluable. It dose not matter if this information is documented.
    Thank you

  • How to get the position of a selected cell in a table ?

    Hi,
    How can I get the position of a selected cell in a table or in a list multicolumn cmd ?
    Thanks.

    Invoke node >>> point to Row Column
    Ben
    Message Edited by Ben on 07-19-2007 03:14 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Point_To_Row_Column.PNG ‏22 KB

  • Please, How do i get the values from a h:selectManyCheckbox ?

    How do i get the values (selected or not) of a <h:selectManyCheckbox> tag and show them .For instance
    i have the folowing options :
    <h:selectManyCheckbox
                           id="cartas"
                       layout="pageDirection"
                        value="#{store.cartas}">
          <f:selectItems
                        value="#{cartas}"/>
        </h:selectManyCheckbox>
        <h:message styleClass="validationMessage" for="newsletters"/>with my faces-config.xml:
    <managed-bean>
        <description></description>
        <managed-bean-name>cartas</managed-bean-name>
        <managed-bean-class>java.util.ArrayList</managed-bean-class>
        <managed-bean-scope>application</managed-bean-scope>
        <list-entries>
          <value-class>javax.faces.model.SelectItem</value-class>
          <value>#{cartas0}</value>
          <value>#{cartas1}</value>
          <value>#{cartas2}</value>
          <value>#{cartas3}</value>
        </list-entries>
      </managed-bean>
      <managed-bean>
        <managed-bean-name>cartas0</managed-bean-name>
        <managed-bean-class>javax.faces.model.SelectItem</managed-bean-class>
        <managed-bean-scope>none</managed-bean-scope>
        <managed-property>
          <property-name>label</property-name>
          <value>Semanal</value>
        </managed-property>
        <managed-property>
          <property-name>value</property-name>
          <value>200</value>
        </managed-property>
      </managed-bean>
      <managed-bean>
        <managed-bean-name>cartas1</managed-bean-name>
        <managed-bean-class>javax.faces.model.SelectItem</managed-bean-class>
        <managed-bean-scope>none</managed-bean-scope>
        <managed-property>
          <property-name>label</property-name>
          <value>As bruxas</value>
        </managed-property>
        <managed-property>
          <property-name>value</property-name>
          <value>201</value>
        </managed-property>
      </managed-bean>
      <managed-bean>
        <managed-bean-name>cartas2</managed-bean-name>
        <managed-bean-class>javax.faces.model.SelectItem</managed-bean-class>
        <managed-bean-scope>none</managed-bean-scope>
        <managed-property>
          <property-name>label</property-name>
          <value>Exercise</value>
        </managed-property>
        <managed-property>
          <property-name>value</property-name>
          <value>202</value>
        </managed-property>
      </managed-bean>
      <managed-bean>
        <managed-bean-name>cartas3</managed-bean-name>
        <managed-bean-class>javax.faces.model.SelectItem</managed-bean-class>
        <managed-bean-scope>none</managed-bean-scope>
        <managed-property>
          <property-name>label</property-name>
          <value>Gusman Park</value>
        </managed-property>
        <managed-property>
          <property-name>value</property-name>
          <value>203</value>
        </managed-property>
      </managed-bean>Thanks for the atention!! All the best!!

    Hi,
    In your backing bean you will need to add a new variable to bind your control to, I think this variable needs to be of teh "HtmlSelectManyCheckbox" type. The on your jsp page you can add binding="#{myBean.myVariable}".
    When you want to get the values of the selectMany in your backing bean, you can call the getSelectedValues() function on your HtmlSelectManyCheckbox variable.
    in backing bean:
    private HtmlSelectManyCheckbox hsmc;
    public HtmlSelectManyCheckbox getHsmc(){
        return hsmc;
    public void setHsmc(HtmlSelectManyCheckbox hsmc){
        this.hsmc = hsmc;
    public void someFunction(){
       Object[] obs = hsmc.getSelectedValues();
    }On jsp page:
    <h:selectManyCheckbox
                           id="cartas"
                       layout="pageDirection"
                        value="#{store.cartas}"
                         binding="#(myBean.hsmc}">
          <f:selectItems
                        value="#{cartas}"/>
        </h:selectManyCheckbox>

  • How we can get the values  from one screen to another screen?

    hi guru's.
         how we can get the values  from one screen to another screen?
              we get values where cusor is placed but in my requirement i want to get to field values from one screen to another screen.
    regards.
      satheesh.

    Just think of dynpros as windows into the global memory of your program... so if you want the value of a field on dynpro 1234 to appear on dynpro 2345, then just pop the value into a global variable (i.e. one defined in your top include), and you will be able to see it in your second dynpro (assuming you make the field formats etc the same on both screens!).

  • How do I get the values from a form?

    How do I get the values from a form?

    You can try using request method..
    request.getParameter("yourFormInputName");
    Try this.

  • How to get the values from html:select? tag..?

    i tried with this, but its not working...
    <html:select styleClass="text" name="querydefs" property="shortcut"
                 onchange="retrieveOptions()" styleId="firstBox" indexed="true">
    <html:options collection="advanced.choices" property="shortcut" labelProperty="label" />
    </html:select>
                        <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>

    <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>This java script is not working at all..its not printing anything in document.write();
    This is code..
    <td class="rowcolor1" width="20%">
    <html:select styleClass="text" name="querydefs" property="shortcut"
                             onchange="retrieveSecondOptions()" styleId="firstBox"
                             indexed="true">
                             <html:options collection="advanced.choices" property="shortcut"
                                  labelProperty="label"  />
                        </html:select>i tried with this also. but no use..i'm not the getting the seleced option...
    function retrieveOptions(){
    firstBox = document.getElementById('firstBox');
                             if(firstBox.selectedIndex==0){
          return;
        selectedOption = firstBox.options[firstBox.selectedIndex].value;
    }actually , how to get the values from <html:select> ...?
    my idea is to know which value is selected from the combo box(<html:select> ) if that value is equal some string i have enable a hyperlink to open a popup window

  • How can I get the value of "Warehose" column in a form

    How can I get the value of "Warehouse" column in the form below (I mean what table that contain this value):
    Production Supervisor >> Batches >> (Button) Material Details >> (Button) Line Allocations
    Well, for more clearly! My problem is I must have the Unit Cost of Items, so I've got it in the cm_cmpt_dtl (table), but if I want to, I must create a relation that require 2 filed, they're Item_ID and Whse_Code.
    There's no problem with Item_ID, but Whse_Code seem to be the Mission Impossible (hix, I hate that film!!!!)
    I wonder if It was right to post this topic here. But anyway I just post my question here, hope I could get some help.

    wow, many, many, many.... and many thanks!
    Just add a tiny modify to check out the Batch_type
    doc_id = (select batch_id from gme_batch_header where batch_no='&batch_number' and batch_type = 0)
    Because the batch_no can be duplicated as we also create Batch and Filrm Planned Order.
    Many thanks for your support!
    P/S: Sorry for my terrible English :P

  • How can we get the value of the key field in a custom data model using governance API?

    Dear Team,
    How can we get the value of the key field in a custom data model, to be used for manipulation of the change request fields using governance API?
    Any kind of help would be sincerely appreciated.
    Thanks & Regards,
    Tushar.

    Hi Michael,
    Thanks for direction. Let me give more context on this as I'm interested to get more details..One of the issue was to read cross entity field values on UI based on user action and set other entity field behaviour...It is similar to what is being posted here.
    For ex: Reading MTART from Basic Data UIBB in MM MDG UI and set the field properties in some other custom entities say ZZETEST. This cannot be done using UI BADI as it only supports single entity at a time and not cross entity. So alternatively we found a solution where we can enhance existing PLMB feederclass cl_mdg_bs_mat_feeder_form by reading the model and the entity as needed as it it proved that it supports cross entity UI field behaviours and so business requirements.
    This is a workaround for now.
    So the question is How do we achive it using governance API for cross entity field behiaviours.?or what is the right way doing this.
    Can we do that using governance API and its' methods?
    In the Governance API doc you provided below has referring to below external model as part of gevernance API.
    The active or inactive data (before or during the derivation or the check) can be read
    with the external data model interface IF_USMD_MODEL_EXT with the method READ_CHAR_VALUE and
    the corresponding READ_MODE parameter. To avoid unnecessary flushes (derivations), the NO_FLUSH
    parameter should b
    e set to ‘X’.
    Thanks
    Praveen

  • How can i get the value stored in the session object using its sessionid

    how can i get the value stored in the session object using its sessionid by running stand alone java application

    myforum wrote:
    how can i get the value stored in the session object using its sessionid by running stand alone java applicationThis does not seem to make sense! You need at least to give a lot more detail of what you are doing.

  • How do i get the value  of that field

    in JSP i have a field like below..
    <input type="hidden" id="grpId<%=Index%>" value="<bean:write name='GrpList' property='groupId'/>"/>
    In Action class , how do i get the value of that field (i.e id) ?
    String value =reques.getparameter (//what ??);

    i dont want to change the jsp.
    concern is , as the name of the id is dynamic .....so can i get the value in the Action class ?
    is there any trick exists ?
    I will try not to change any jsp code but will do changes in Action class
    Message was edited by:
    Unknown_Citizen

  • How can we get the values from the view?

    Hi All,
    my scenario is i have two fields in my view .one is parameter.and another on is select-options.how can i get the user entered values into my selection screen.?
    for the select options i get the values into field-symbol.for parameter i get the value using get_attribute.
    can i use like this in select statement.
    WHERE SERVICE_ID  = ZSD_DD_AUFNRS
                       AND CRE_DT IN <FS_DATE>.
    Regards,
    Ravi.

    Hi Sravan,
    when i am using the below code to generate self defined functions i m getting a error .
    *Generate an object for self defined functions
      DATA: lo_self_functions TYPE REF TO if_salv_wd_function_settings,
    *Generate an object for button 'Confirm'
           lr_button TYPE REF TO cl_salv_wd_fe_button,
           lo_self_function TYPE REF TO cl_salv_wd_function,
                  l_text type string.
    *Set Self-defined functions
    *'Confirm' Button
      lo_self_functions ?= l_value..
      lo_self_function = lo_self_functions->create_function( 'CONFIRM'  ).
      CREATE OBJECT lr_button.
      CLEAR l_text.
      l_text = 'Confirm'.
      lr_button->set_text( l_text ).
      lr_button->set_image_source( '' ).
      lr_button->set_image_first( 'X' ).
      lo_self_function->set_editor( lr_button ).
    Error when processing your request
    What has happened?
    The URL http://cgslsvr3.cgsl.com:8020/sap/bc/webdynpro/sap/zsdr_cash_work_list/ was not called due to an error.
    Note
    The following error text was processed in the system CGD : WebDynpro Exception: IDs Can Only Contain Characters of Syntactical Character Set
    The error occurred on the application server cgslsvr3_CGD_20 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: RAISE of program CX_WD_GENERAL=================CP
    Method: CONSTRUCTOR of program CL_WDR_VIEW_ELEMENT===========CP
    Method: CONSTRUCTOR of program CL_WD_TOOLBAR_BUTTON==========CP
    Method: NEW_TOOLBAR_BUTTON of program CL_WD_TOOLBAR_BUTTON==========CP
    Method: IF_SALV_WD_COMP_TABLE_UI~CREATE_TOOLBAR_ITEM of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_UI~CREATE_TOOLBAR_ITEMS of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_UI~UPDATE_TOOLBAR_ITEMS of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_UI~UPDATE_TOOLBAR of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_UI~UPDATE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_VIEW~MODIFY of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    What can I do?
    If the termination type was RABAX_STATE, then you can find more information on the cause of the termination in the system CGD in transaction ST22.
    If the termination type was ABORT_MESSAGE_STATE, then you can find more information on the cause of the termination on the application server cgslsvr3_CGD_20 in transaction SM21.
    If the termination type was ERROR_MESSAGE_STATE, then you can search for more information in the trace file for the work process 0 in transaction ST11 on the application server cgslsvr3_CGD_20 . In some situations, you may also need to analyze the trace files of other work processes.
    If you do not yet have a user ID, contact your system administrator.
    Error code: ICF-IE-http -c: 110 -u: CT-0024 -l: E -s: CGD -i: cgslsvr3_CGD_20 -w: 0 -d: 20080414 -t: 105835 -v: RABAX_STATE -e: UNCAUGHT_EXCEPTION
    HTTP 500 - Internal Server Error
    Your SAP Internet Communication Framework Team
    How can i resolve it?
    Regards,
    Ravi

  • How do i get the value in a variable that I don't know the name of til run

    I have a record type( pr_team) defined in a package - anchored to a table.
    I want to be able to go through each of the fields in it one at a time. I get the list of fields from the table definition from cursor as follows
    CURSOR c_fields IS
    SELECT column_name
    FROM all_tab_cols
    WHERE owner = 'CDS'
    AND table_name = 'TEAM';
    r_fields c_fields%ROWTYPE;
    So first returned value is team_id
    how can I get this value when all I know the field name is 'pr_team.' || r_fields.column_name
    cheers
    Simon

    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3     r_emp emp%ROWTYPE;
      4  END package_name;
      5  /
    Package created.
    SQL> SET SERVEROUTPUT ON SIZE UNLIMITED;
    SQL> DECLARE
      2     v_empno emp.empno%TYPE;
      3     v_ename emp.ename%TYPE;
      4  BEGIN
      5     SELECT *
      6     INTO   package_name.r_emp
      7     FROM   emp
      8     WHERE  ROWNUM = 1;
      9
    10     EXECUTE IMMEDIATE
    11        'BEGIN ' ||
    12        '   :v_empno := package_name.r_emp.empno; ' ||
    13        '   :v_ename := package_name.r_emp.ename; ' ||
    14        'END;'
    15        USING OUT v_empno, OUT v_ename;
    16
    17     DBMS_OUTPUT.PUT_LINE ('v_empno => ' || v_empno);
    18     DBMS_OUTPUT.PUT_LINE ('v_ename => ' || v_ename);
    19  END;
    20  /
    v_empno => 7369
    v_ename => SMITH
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for

  • HP Officejet 4315 All-in-One

    I have an HP Officejet 4315 All-in-One that I bought several computers ago.  I now have 2 computes that have Windows 8.1 on them, and the installation disc is for Windows 2000 and Windows XP.  The installation disc says that my system doesn't have wh

  • [SOLVED] Attempting to boot from USB key in UEFI mode

    I am attempting to boot from a USB Key in UEFI mode to dual boot windows 8 and arch linux.  I'm unsuccessful in getting the USB key to boot in UEFI mode.  I am following the guide on page: https://wiki.archlinux.org/index.php/Un - _Interface due to t

  • Can´t open, rename, copy or delete PDF file

    I have got a problem opening, renaming, moving, copying and even deleting a PDF file with a very long file name. It does not upload either, so I cannot send it to Adobe via the Support form. I have now downloaded a PDF repair application, but I get t

  • Check if Custom Permission level exists or not

    I have cretaed a custom permission level. On feature activation, i need to check if that custom permission level exists or not. How can i do that? Thanks, Avni Bhatt

  • When sharing a videos I get a rendering error: -50.  Any suggestions?

    when sharing a videos I get a rendering error: -50.  Any suggestions?