Showing posts with label DATAGRIDVIEW. Show all posts
Showing posts with label DATAGRIDVIEW. Show all posts

Wednesday, May 14, 2014

DATAGRIDVIEW ROW FORMATING

SAMPLE:

Private Sub dgvData_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvData.CellFormatting

        If dgvData.DataSource IsNot Nothing Then
            Dim drv As DataRowView
            Dim dt As DataTable = CType(dgvData.DataSource, DataSet).Tables(0)

            If e.RowIndex >= 0 Then
                If e.RowIndex <= dt.Rows.Count - 1 Then
                    drv = dt.DefaultView.Item(e.RowIndex)
                    Dim dfm As Date

                    Dim dto  As Date
                    dfm = drv.Item("Period From")
                    dto  = drv.Item("Period Upto")                      
                    If Now.Date >= dfm And Now.Date <= dto Then
                        e.CellStyle.ForeColor = dgvData.DefaultCellStyle.ForeColor
                    Else
                        e.CellStyle.ForeColor = SystemColors.GrayText
                    End If
                End If
            End If
        End If
    End Sub

Thursday, March 14, 2013

Set DataGridView Row Height

Dim xRow as DataGridViewRow = DataGridView1.Rows(DataGridView1.Rows.Add())
'//after assigning cell values use following statement
xRow.Height = xRow.GetPreferredHeight(xRow.Index, DataGridViewAutoSizeRowMode.AllCells, False)