PDA

View Full Version : ستون های دیتاگرید



samiasoft
یک شنبه 15 اسفند 1395, 13:32 عصر
سلام دوستان

فرض کنید در یک تکست باکس مقدار قیمت یک کالایی بصورت 150000 هست.چگونه اینو بصورت 150,000 نمایش بدم؟

همچنین این تغییر رو برای یکی از ستون های دیتاگرید چگونه میشود انجام داد ؟

ممنون میشوم راهنمایی کنید.

samiasoft
یک شنبه 15 اسفند 1395, 17:37 عصر
بالاخره دستورشو اینطور نوشتم و درست شد :

برای تکست باکس :


Dim n As Double = TextBox1.Text
TextBox1.Text = n.ToString("###,###")
TextBox1.Select(TextBox1.Text.Length, 0)



برای دیتاگرید :


Private Sub moneycell()
Dim newStyle As New DataGridViewCellStyle
newStyle.Format = "###,###"
DataGridView1.Columns(1).DefaultCellStyle.ApplySty le(newStyle)


End Sub
Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) Handles DataGridView1.CellFormatting
If Not IsNothing(e.Value) Then
If IsNumeric(e.Value) Then
e.Value = Format(CDbl(e.Value), e.CellStyle.Format)
End If
End If
End Sub