LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read in the new entered value from the table

Hello,
I have a 3x7 table.  Column 1 is for label, and column 2 and 3  are for storing doubles.  I was able to manipulate the cursor, to put it where I want on the right cell, and able to change the values on the table (column 2 and 3) graphically.  But when the program tried to read in the new entered value from the cell using GetTableCellVal, all the data read in were zeroes  (zeroes were the initial values).  And the function returned zero that indicated a success call.
Please show me how I can read in the new values from the table.  Thank you.
 
Here is my code:
 switch (event)
 {
  case EVENT_KEYPRESS:
   GetCtrlAttribute(panel, PANEL_CAL_MANUAL_CAL_TABLE, ATTR_TABLE_RUN_STATE, &state);
   if (state == VAL_EDIT_STATE) {
    keyCode = GetKeyPressEventVirtualKey(eventData2);
    if (keyCode == VAL_ENTER_VKEY) {
     GetActiveTableCell(panel, PANEL_CAL_MANUAL_CAL_TABLE, &cell);
     status = GetTableCellVal(panel, PANEL_CAL_MANUAL_CAL_TABLE, cell, &tempDoubleData);
    //Get the Tx Value from Column 2
    if (cell.x == 2)
     gManualMeas[cell.y-1].mTxVal = tempDoubleData;
    //Get the Rx Value from Column 3
    if (cell.x == 3)
     gManualMeas[cell.y-1].mRxVal = tempDoubleData;
     if (cell.x < 3) {
      cell.x++;
      SetActiveTableCell(panel, PANEL_CAL_MANUAL_CAL_TABLE, cell);
      SetCtrlAttribute(panel, PANEL_CAL_MANUAL_CAL_TABLE, ATTR_TABLE_RUN_STATE, VAL_EDIT_STATE);
     }
     else {
      if (cell.y != 7) {
       SetActiveTableCell(panel, PANEL_CAL_MANUAL_CAL_TABLE, MakePoint(2,cell.y+1));
       SetCtrlAttribute(panel, PANEL_CAL_MANUAL_CAL_TABLE, ATTR_TABLE_RUN_STATE, VAL_EDIT_STATE);
      }
      else {
       SetActiveTableCell(panel, PANEL_CAL_MANUAL_CAL_TABLE, MakePoint(2,1));
       SetCtrlAttribute(panel, PANEL_CAL_MANUAL_CAL_TABLE, ATTR_TABLE_RUN_STATE, VAL_EDIT_STATE);
      }
     }
     return 1;
    }
   }
   break;
}   
0 Kudos
Message 1 of 7
(3,740 Views)
Hello Dan,

The problem you're having is because you are trying to read in the value in the wrong event (KEYPRESS). You should be using the COMMIT event. The KEYPRESS event is only sent to the control callback in order to give the programmer a chance to filter the key before the control actually processes the key.

Your code can be a lot simpler that what you have in your post. You just need to call GetTableCellVal when you receive EVENT_COMMIT and pass it the cell whose value changed (the row and column indices of this cell are in eventData1 and eventData2 respectively, as long as only one cell was affected, otherwise the indices will be set to 0 -- a paste, or a sort operation, for example might affect multiple cells)

Luis

Message Edited by LuisG on 03-05-2007 05:17 PM

0 Kudos
Message 2 of 7
(3,732 Views)

Hi Luis,

Actually I also had the case EVENT_COMMIT in the same routine but it never hit that one.  They both can be in the same switch(event) right?

Do you know why?  What I am doing is really simple:  a user enter data from cell to cell, and the program only needs to read in the new value and switch to the new cell correctly.  I can switch to the new cell correctly, but cannot read in the new data.

Thank you.

 

0 Kudos
Message 3 of 7
(3,723 Views)
Yes, you certainly can have both events in the same switch statement. And it should hit that event when you modify a cell. Like you said, what you are doing is pretty simple. It should definitely do what you are expecting it to.

Would it be possible for you to attach here a short sample that demonstrates the problem you're seeing? If I can reproduce the problem her I should be able to help you.

Luis
0 Kudos
Message 4 of 7
(3,693 Views)

Hi Luis,

Here is the sample code.  Thanks.

Dan

 

0 Kudos
Message 5 of 7
(3,684 Views)
Thanks, Dan.

In order to understand what is happening, you first need to understand the sequence in which CVI processes a keystroke:

1. the user presses a key
2. an EVENT_KEYPRESS is sent to the callback of the control that has the focus
3. if the event is not swallowed (by returning 1 from the callback), the control then processes the event.
4. Depending on what the control does with the event (this varies according to the type of control) other events are sent to the control's callback; for example, an EVENT_COMMIT.

In your case, you are processing the key event, and as a result you swallow the event. This means that the control never receives the keystroke. Instead, you change the active cell programmatically. Although changing a cell programmatically will ensure that the new value of a pending edit session is commited to the table, it does not result in an event being sent to the callback, since typically events are only sent for changes resulting from interactive actions, as opposed to changes resulting from programmatic actions. This is why you don't receive the commit event.

If I understand your code correctly, you want to override the default behavior of the key by navigating through the table horizontally instead of vertically. I can think of two ways of doing this. The first, which is closest to your current strategy, involves making the following changes:

1. don't swallow the key, but allow it to go to the control; this way you will receive the commit event.
2. instead of changing the active cell inside the keypress event, post a deferred callback that will be called after the commit event is sent. In this callback you can then change the active cell.

I'm attaching a modified version of your code that does this.

The second strategy is a lot simpler, but it relies on what might be a bad assumption on my part of what you're trying to do. If really, all you want to do is to navigate horizontally with the key, you could rely on the fact that that is exactly what the table control does in response to a key being hit. Therefore, you could simply convert the key into a key inside the keypress event. Something like this:

GetCtrlAttribute(panel, PANEL_CAL_MANUAL_CAL_TABLE, ATTR_TABLE_RUN_STATE, &state);
if (state == VAL_EDIT_STATE)
{
keyCode = GetKeyPressEventVirtualKey(eventData2);
if (keyCode == VAL_ENTER_VKEY)
SetKeyPressEventKey (eventData2, VAL_TAB_VKEY, 0, 0, 0, 0);
}

Hope this helps.

Luis
Message 6 of 7
(3,675 Views)

Great!  Thank you very much, Luis!

Dan

 

0 Kudos
Message 7 of 7
(3,667 Views)