Help! how to manipulate datagridview value

witecloner

Well-known member
Joined
Feb 12, 2009
Messages
45
Programming Experience
Beginner
Hi all, i am newbie in vb.net

could anybody tell me how can i format the data in datagridview. to clear this question here above my source.

VB.NET:
Dim sAdapter As New SqlDataAdapter
Dim sCmdBuilder As New SqlCommandBuilder
Dim sDataTable As New DataTable
Dim ConText As string = "Data Source=.\SQLEXPRESS;Initial Catalog=TSMMaspion; Integrated Security = True;Pooling=False"
Dim SqlText As String

Private Sub Form_Load(...)
     SqlText = "SELECT * FROM Divisi"
     sAdapter = new SqlDataAdapter(SqlText, ConText)
     sCmdBuilder = New SqlCommandBuilder(sAdapter) 
     sDataTable = new DataTable()
     sDataTable.Locale = System.Globalization.CultureInfo.InvariantCulture
     sAdapter.Fill(sDataTable)
     DataGridView1.DataSource = sDataTable
End Sub

Result :
-----------------------------------------------------
| ID | Divisi Name | Salary |
------------------------------------------------------
|1 | Staff | 1.000,0000 |
|2 | Cashir | 5.00,0000 |
------------------------------------------------------

How can i manipulate the salary value? i mean i just want to display 2 digit precision in datagridview table.

Thank you
 
Em...thanks for all. i have find this question.

Maybe some other want to know how to do it. The DataGridView cell value can be modified through DataGridView_CellFormatting Event. and the code is like here :

VB.NET:
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting

    If Me.DataGridView1.Columns(e.ColumnIndex).Name = "Salary" Then
         e.Value = Format(e.Value, "0.00")
    End If

End Sub
 
Back
Top