當我不知道導致此行爲的原因時,很難解釋問題,但我會嘗試。在假期或價值變化時設置控制值
在我的形式有兩種Devexpress SpinEdit controls
(該SpinEdit
類表示由一個文本編輯器的控制和一對旋轉按鈕,用戶可以點擊調整值就像使用NumericUpDown
)
的問題是在處理旋轉編輯1值更改事件後,我無法設置第二個旋轉編輯的值。
當窗體加載的兩個控件從數據庫中獲得的值(十進制18,2)
讓的說:
priceSpinEdit值爲100,00
discountSpinedit值是10,00
當用戶更改折扣百分比時,我需要用折扣計算價格並將價格轉換成priceWithDiscountSpinEdit
I h AVE代碼工作的順利
private void supplierDiscountPercetangeSpinEdit_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
decimal price, percentage, calculatedPrice;
price = (decimal)supplierPriceSpinEdit.EditValue;
percentage = Convert.ToDecimal(e.NewValue, CultureInfo.InvariantCulture);
calculatedPrice = Popust.Izracunaj(price, percentage);
supplierPriceWithDiscountSpinEdit.EditValue = calculatedPrice;
}
雖然焦點設置在其中我做計算supplierPriceWithDiscountSpinEdit顯示正確的計算值控制,但這種控制失去之後第二個重點值設置爲從數據庫加載值。
我在想,我需要寫的值對象,但後來我試圖把這個成簡單的按鈕,點擊它工作的(價值棒的)
private void button1_Click(object sender, EventArgs e)
{
decimal price, percentage, calculatedPrice;
price = (decimal)supplierPriceSpinEdit.EditValue;
percentage = (decimal)supplierDiscountPercetangeSpinEdit.EditValue;
calculatedPrice = Popust.Izracunaj(price, percentage);
supplierPriceWithDiscountSpinEdit.EditValue = calculatedPrice;
}
所以我的問題是,爲什麼計算價格正確的值時,在第二個spinEdit中顯示,並在失去焦點後消失。
對不起,如果有必要,我可以添加更多信息。
編輯:spinedit控制
//
// supplierPriceWithDiscountSpinEdit
//
this.supplierPriceWithDiscountSpinEdit.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.productBindingSource, "SupplierPriceWithDiscount", true));
this.supplierPriceWithDiscountSpinEdit.EditValue = "0,00";
this.supplierPriceWithDiscountSpinEdit.EnterMoveNextControl = true;
this.supplierPriceWithDiscountSpinEdit.Location = new System.Drawing.Point(527, 33);
this.supplierPriceWithDiscountSpinEdit.MenuManager = this.barManager1;
this.supplierPriceWithDiscountSpinEdit.Name = "supplierPriceWithDiscountSpinEdit";
this.supplierPriceWithDiscountSpinEdit.Properties.Mask.BeepOnError = true;
this.supplierPriceWithDiscountSpinEdit.Properties.Mask.EditMask = "n2";
this.supplierPriceWithDiscountSpinEdit.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
this.supplierPriceWithDiscountSpinEdit.Properties.Mask.UseMaskAsDisplayFormat = true;
this.supplierPriceWithDiscountSpinEdit.Properties.NullText = "0,00";
this.supplierPriceWithDiscountSpinEdit.Properties.ValidateOnEnterKey = true;
this.supplierPriceWithDiscountSpinEdit.Size = new System.Drawing.Size(100, 20);
this.supplierPriceWithDiscountSpinEdit.TabIndex = 13;
供應商是否有權利使用數據綁定? – SidAhmed
是的,十進制(18,2)也 – Carlo
您可以顯示代碼在哪裏綁定supplierPriceWithDiscountSpinEdit控件? – SidAhmed