2015-08-28 49 views
0

我在網格 a 真編輯,我設置自動聲明是的。如何從RealEdit的窗體網格中獲取並設置實際值?

名稱爲myRealEdit數據源爲myTablemyRealField

修改方法我想要得到的值,我需要做一個如果控制。

如果該值爲0,則更改歸檔的值如果該值不是0 會拋出輸入的值並恢復以前的值。

我用這個代碼,在改性方法:

public boolean modified() 
{ 
boolean ret; 
real storedValue; 

ret = super(); 

storedValue = myTable.myRealField; // there is another way to get the value ? 

if (myRealEdit.valueStr() == "0") 
//accept the value 

if (!myRealEdit.valueStr() != "0") 
{ 
myRealEdit.realValue(storedValue); 
} 

return ret; 
} 

如果該值不爲0(零)不恢復以前的值。我不得不使用另一種方法嗎?還有另一種方法來獲得真正的價值?

謝謝諮詢,

享受!

+0

上了一個臺階,你想完成什麼? 由於您的代碼被完全破壞,很難扣除您嘗試的內容。 我可以猜測:你不會接受零值。你是否考慮過表格字段,數據源字段或控件上的'Mandatory'屬性? –

+0

謝謝@ JanB.Kjeldsen對您的評論。 我想只接受0值,在另一種情況下,我再次將值設置爲以前的值。 例如:我存儲了值50,如果我把值80,我不接受這個值,並在_myRealEdit_ – ulisses

+0

中恢復50但我不知道如何從_myRealEdit_ – ulisses

回答

1

既然您在回答中使用了modified方法,我想您要將此字段驗證放在控件級別(而不是數據源或表級別)上。

作爲@Jan B. Kjeldsen在他的評論中建議,你應該使用validate方法來做這個驗證。只有當您想要添加除字段值修改以外還執行的某些邏輯時,才使用modified方法。

validate方法看上去就像

public boolean validate() 
{ 
    return this.realValue() == 0 && super() || checkFailed(strFmt("Value %1 is not permitted", this.realValue())); 
    // TODO please replace this with a Label and explain to the user why the value is not permitted and what he or she can do to resolve this 
} 
+0

謝謝大家,工作順利! – ulisses

0

我找到一個可行的辦法,

我用這個代碼:

public boolean modified() 
{ 
boolean ret; 

if (myRealEdit.valueStr() == "0") 
{ 
//accept the value 
    ret = super(); 
} 
if (!myRealEdit.valueStr() != "0") 
{ 
    info("Value not permit"); 
    // nothing to do 
} 
return ret; 
} 

這樣,當且僅當我有一個值0我修改的值。

我需要獲取或讀取從修改方法中的myRealEdit插入的實際值。

如果社區有插入評論或改進,將會有更多的信息。

+0

與Jan B. Kjeldsen建議的一樣,改用'validateField'方法,如果此方法返回'false',則該字段將自動重置爲其以前的值。 此外,請勿使用'valueStr()'獲取實際控件的值。改用'realValue()'並將其與實際值進行比較。如果(!myRealEdit.valueStr()!=「0」)表達式不符合你的描述(我很困惑它爲什麼會爲你編譯,我得到一個操作數類型編譯錯誤,因爲一個布爾值不能與字符串進行比較)。 –

+0

測試'valueStr()'而不是'realValue()'感覺不對。 –

相關問題