0

以下の回答を使用して、Visual Basic 2010 DGV で 10 進数値を表示しました。

コードを使用して、DataGridView.DefaultCellStyle プロパティを設定できます。

デザイナーでこれを行うこともできます。

1.Right clicking your DGV and select Edit Columns. The Edit Columns dialog appears.
2.Select your column on the left side of the dialog and click the DefaultCellStyle property field to bring up the CellStyle Builder.
3.In the Builder dialog click Format which brings up the Format String Dialog.
4.Make your selections in this dialog (select Numeric type, which allows specifying number of decimals to display) and save your changes.

私の問題は、DGV にバインドされたテキスト ボックスを介して新しい値を入力すると、DGV は小数点以下の桁数を表示しますが、入力した実際の値は表示しません。例 : 20.25 と入力し、保存ボタンをクリックします。DGV では 20.25 の値が表示されます。プログラムを閉じて再度開くと、DGV の値は入力した 20.25 ではなく 20.00 と表示されます。

この問題を解決するにはどうすればよいですか?

4

1 に答える 1

0

私はこの解決策を簡単に見つけました.2日間にわたって検索し、最終的に見つけました. -データベースの列の型は、Money または number,double,single でなければなりません。-datagridview イベント "CellFormatting" を次のコードのように更新します。

private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
   {
       if (this.dataGridView2.Columns[e.ColumnIndex].Name == "Aidat")
       {
          string deger=(string)e.Value;
          deger = String.Format("{0:0.00}", deger);
       }
   }
于 2013-04-14T08:25:25.367 に答える