将“借记栏"(DataGridView)中的数字条目格式化为具有累赘性 [英] Format numeric entries in a Debit Column (DataGridView) to negetive

查看:125
本文介绍了将“借记栏"(DataGridView)中的数字条目格式化为具有累赘性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体应用程序中有一个DatagridView,用于帐户交易.

我希望每当用户在借方"列中输入数字时,该数字立即转换为一个有意思的数字(例如500到-500)并显示该有意思的数字.

拜托,我该怎么做?我整天尝试都没有成功.

我正在使用VS 2008,SQL Server 2008,Typed DataSet和WinForms UI.

谢谢.

I have a DatagridView in a Windows forms application which is used for account transactions.

I want that whenever user enters a number in the Debit Column, it gets converted to a negetive number (eg 500 to -500) immediately and display the negetive number.

Please, how do I do that? I have tried all day without success.

I am using VS 2008, SQL Server 2008, Typed DataSets, and WinForms UI.

Thank you.

推荐答案

在会计应用程序中,通常在括号中使用负数(500),而不是-500.

可以通过处理其中一种事件(例如RowLeave,SelectionChanged或CellEndEdit)来轻松实现此目的,无论哪种最适合您的实现
In an accounting application a negative number is usually enclosed in parentheses, (500) rather than -500.

This can easily be accomplished by handling one of the events, like RowLeave, SelectionChanged or CellEndEdit, whatever is the most appropriate for your implementation


作为多年的会计师,我觉得有必要告诉你说你的方法是错误的.

负借方是贷方.

您不必在列中放置负数,所有数字都是绝对值,Signed元素由其所在的列决定.
(重复输入会计101).

(您可以在栏中输入减号,但这些都是冲销.)


例如...

您有银行余额,贷方(即收据在右列)和借方(即付款在左列)的记录.
然后,您将有一个成本分类帐,其中包含反向条目.

因此,您要进行货款付款,付款在银行帐户的左列和成本帐户的右列显示为£300.

您要显示负号(即放在方括号中)的唯一原因是当您显示资产负债表并且在列中具有一组成本.

重复输入法已有800多年的历史了,因此有很多网站展示了它的工作原理.

这是一个示例 [ ^ ]

如您所见,左边是借方,右边是贷方,都是绝对值.
As an accountant of many years standing I feel obliged to tell you that your approach is wrong.

A negative Debit is a Credit.

You do not put a negative number in a column, all numbers are absolute values, the Signed Element is decided by the column it is in.
(Double Entry Accounting 101).

(You can have minus numbers in a column, but these are exclusively Reversals.)


Eg...

You have a record for Bank Balance, credits (ie receipts go in the right hand column), and debits (ie payments go in the left).
Then you have a cost ledger which has the reverse entries.

Thus you make a payment for goods, the payment shows as £300 in the left column of the bank account, and the right column of the cost account.

The only reason you would show minus numbers (ie in Brackets) is when you are showing a Balance Sheet, and have a set of costs in a column.

Double Entry has been around for about 800 years, so there are plenty of websites showing how it works.

Here is an Example[^]

As you see, Debit on the left, credit on the right and all are absolute values.


如果必须执行此操作,请使用DataGridView.OnCellFormatting事件.像这样的东西:

If you have to do this, use the DataGridView.OnCellFormatting event. Something like this:

private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex == dgvCustomers.Columns["Debit"].Index)
    {
        e.Value = -(Math.Abs(e.Value));
        // IMPORTANT to do the next line to show that it has been handled.
        e.FormattingApplied = true;
    }
}



我已经把它写在了我的头上.该方法是正确的,但我可能记错了一些方法/属性名称.

祝你好运! :)



I have written this off the top of my head. The methodology is correct but I may have misremembered some of the method/property names.

Good Luck! :)


这篇关于将“借记栏"(DataGridView)中的数字条目格式化为具有累赘性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆