2016-11-06 2 views
0

내가된 DataGridView 셀 형식 1000 단위 구분

DefaultCellStyle.Format = "N2" 
DefaultCellStyle.Format = "#,###.##" 

아무것도가 보여주는 유지하는 것 일하지 난 이미 시도 것을이 123,456,789.12 같은 1000 단위 구분 2 소수점을 표시 VB.NET datagridview 셀을 포맷 할 123456789.12

참고 : 데이터베이스에서 datagridview을 채우고 있습니다. 동적으로 셀 형식을 변경해야합니다.

+1

을 확인할 수 있습니다 NVARCHAR (문자열)로 볼 수 있지만, 둘 중 하나는 일 것으로 보인다 숫자가있는 열에. 텍스트 데이터 형식이 지정되지 않을 것이므로 아마 그 숫자 열에 할당해야합니다. – Plutonix

답변

0

열 유형이 숫자 유형 인 경우 (예 : do uble), formating은 편집 모드와 관계없이 작업을 수행합니다. 당신의 열 유형이 디폴트로 문자열 유형 인 경우 , 당신은 C#에서 다음과 같은 트릭 작업을 수행 할 cellFormating 이벤트를 처리 갈까요 :

private void DgvCellStyle_Load(object sender, EventArgs e) 

    { 

     DataTable dt = new DataTable(); 

     dt.Columns.Add("a"); 

     dt.Rows.Add(155.6565); 

     dt.Rows.Add(2342.2); 

     this.dataGridView1.DataSource = dt; 



     this.dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting); 

    } 



    void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 

    { 

     if (e.ColumnIndex == 0 && e.RowIndex != this.dataGridView1.NewRowIndex) 

     { 

      double d = double.Parse(e.Value.ToString()); 

      e.Value = d.ToString("N2"); 

     } 

    } 

이 나를 위해 작동이에서와 같이 내가 데이터를 검색으로 데이터베이스 및 DataGridView에이

당신은 두 번째는` "#, ###. 00"`해야이 https://social.msdn.microsoft.com/Forums/windows/en-US/95e7e7ef-2e71-412f-abe5-ffbee2c12c18/how-to-format-datagridview-columns-to-numeric-columndefaultcellstyleformat-does-not-work?forum=winformsdatacontrols