Changing row or column status programmatically

You might need to change the status of a row or column programmatically. Typically, you do this to prevent the default behavior from taking place. For example, you might copy a row from one DataWindow to another; and after the user modifies the row, you might want to issue an UPDATE statement instead of an INSERT statement.

You use the SetRowStatus method to programmatically change a DataWindow's row status information. Use the GetRowStatus method to determine the status of a specific row.

You use the SetItemStatus method to programmatically change a DataWindow's column status information. Use the GetItemStatus method to determine the status of a specific column.

Changing column status

You use SetItemStatus to change the column status from Modified to NotModified, or vice versa.

NoteChange column status when you change row status Changing the row status changes the status of all columns in that row to NotModified, so if the UpdateData method is called, no SQL update is produced. You must change the status of columns to be updated after you change the row status.

Changing row status

Changing row status is a little more complicated. The following table illustrates the effect of changing from one row status to another.

Table 3-7: Effects of changing from one row status to another

Specified Status

Original Status

Resulting Status

Result

Modified

New

Modified

Expected

Modified

NewAndModified

Modified

Expected

Modified

NotModified

Modified

Expected

NewAndModified

New

NewAndModified

Expected

NewAndModified

Modified

NewAndModified

Expected

NewAndModified

NotModified

NewAndModified

Expected

New

NewAndModified

NewAndModified

No change

New

Modified

NewAndModified

Different

New

NotModified

New

Expected

NotModified

Modified

NotModified

Expected

NotModified

New

New

No change

NotModified

NewAndModified

New

Different

In the preceding table, the word Expected in the Result column means that the row status is changed to the specified status. For example, issuing SetRowStatus to change the status to Modified or NewAndModified always succeeds.

No change means that the change is not valid and the status is not changed. For example, issuing SetRowStatus on a row that has the status New to change the status to NotModified does not change the status.

Different means that the resulting status is different from both the original and the specified status. For example, issuing SetRowStatus on a row that has the status Modified to change the status to New changes the status to NewAndModified.

Changing a row's status to NotModified or New causes all columns in that row to be assigned an ItemStatus of NotModified. Change the column’s status to Modified to ensure that an update results in a SQL Update.

NoteChanging status indirectly When you cannot change to the desired status directly, you can usually do it indirectly. For example, change New to Modified to NotModified.