我的DBGrid控件是否通过数据源即DataSource和ADODataset邦定在一起的,如今我做的是“退货”功能,我希望用户输入正数,而实际数据库中保存为负数。可否通过设置DBGrid的显示格式等方式来实现呢?请高手指点。

解决方案 »

  1.   

    通过设置DBGrid的显示格式等方式来实现呢?
    --肯定不行的吧.
    在BeforePost事件中控制吧
      

  2.   

    但是在BeforePost事件中将其赋为负值,用户不就看到负数了吗?它也许会觉得很奇怪,为什么输入正数却变为了负数。我是希望网格里显示为负数,而数据库中实际为正数。大家帮我想想办法。
      

  3.   

    可以在表中多加一个符号标志字段~~过去是 Sum(Money),现在可以是 Sum(Money * Sign)
      

  4.   

    procedure TForm1.Table1AfterOpen(DataSet: TDataSet);
    begin
      TNumericField(DataSet.FieldByName('你的字段名')).DisplayFormat := '#;#;#';
    end;procedure TForm1.Table1BeforePost(DataSet: TDataSet);
    begin
      DataSet.FieldByName('你的字段名').AsFloat :=
        -Abs(DataSet.FieldByName('你的字段名').AsFloat);
    end;
      

  5.   

    Specifier Represents
    0 Digit place holder. If the value being formatted has a digit in the position where the '0' appears in the format string, then that digit is copied to the output string. Otherwise, a '0' is stored in that position in the output string.
    # Digit placeholder. If the value being formatted has a digit in the position where the '#' appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string.
    . Decimal point. The first '.' character in the format string determines the location of the decimal separator in the formatted value; any additional '.' characters are ignored. The actual character used as a the decimal separator in the output string is determined by the DecimalSeparator global variable. The default value of DecimalSeparator is specified in the Number Format of the International section in the Windows Control Panel.
    , Thousand separator. If the format string contains one or more ',' characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of ',' characters in the format string does not affect the output, except to indicate that thousand separators are wanted. The actual character used as a the thousand separator in the output is determined by the ThousandSeparator global variable. The default value of ThousandSeparator is specified in the Number Format of the International section in the Windows Control Panel.
    E+ Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-' are contained in the format string, the number is formatted using scientific notation. A group of up to four '0' characters can immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the minimum number of digits in the exponent. The 'E+' and 'e+' formats cause a plus sign to be output for positive exponents and a minus sign to be output for negative exponents. The 'E-' and 'e-' formats output a sign character only for negative exponents.
    'xx'/"xx" Characters enclosed in single or double quotes are output as-is, and do not affect formatting.
    ; Separates sections for positive, negative, and zero numbers in the format string.
      

  6.   

    谢谢zswangII的帮助,设置了TNumericField(DataSet.FieldByName('你的字段名')).DisplayFormat := '#;#;#';过后,负数确实显示为正数了,但麻烦又来了,我有一个字段是货币,加了格式后人民币符号不见了,有没有办法解决?
      

  7.   

    我试了一下,用DisplayFormat := '#;#'和‘#;#;#’是一样的,它们没有区别吗,
    帮助文档也看了,可是英文差,能否帮忙解释一下。请问有QQ吗
      

  8.   

    谢谢zswangII的帮助,问题终于解决了。
      

  9.   

    to 901123456:自己测试吧,情况不多,看看就会了~~begin
      ShowMessage(FormatFloat('"正"0;"负"0;"零"0', +1));
      ShowMessage(FormatFloat('"正"0;"负"0;"零"0', -1));
      ShowMessage(FormatFloat('"正"0;"负"0;"零"0', 0));  ShowMessage(FormatFloat('"正"00.00;"负"00.00;"零"00.00', +1));
      ShowMessage(FormatFloat('"正"00.00;"负"00.00;"零"00.00', -1));
      ShowMessage(FormatFloat('"正"00.00;"负"00.00;"零"00.00', 0));  ShowMessage(FormatFloat('"正"#.00;"负"#.00;"零"#.00', +1));
      ShowMessage(FormatFloat('"正"#.00;"负"#.00;"零"#.00', -1));
      ShowMessage(FormatFloat('"正"#.00;"负"#.00;"零"#.00', 0));
    end;