Private Sub datagrid_bill_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim cell As TableCell = e.Row.Cells(6)
Dim sendDate As DateTime = Convert.ToDateTime(cell.Text)
Dim diff1 As System.TimeSpan = (DateTime.Now - sendDate)
If (diff1.Days > 3) Then
cell.ForeColor = Color.Red
End If
End If
End Sub
Private Sub DataGridView1_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles DataGridView1.DataBindingComplete
For i As Integer = 0 To DataGridView1.RowCount - 1
If (Convert.ToDateTime(DataGridView1(4, i).Value.ToString()) - DateTime.Now).Days >7 Then
DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub
Private Sub AppliedStyleGrid()
For Each gridRow As DataGridViewRow In datagrid_bill.Rows
Dim deliveryDate As DateTime = Convert.ToDateTime(gridRow.Cells("claimsend_dateout").Value.ToString())
If (deliveryDate - DateTime.Now).Days > 3 Then
gridRow.DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub
Private Sub AppliedStyleGrid()
For Each gridRow As DataGridViewRow In datagrid_bill.Rows
Dim deliveryDate As DateTime = Convert.ToDateTime(gridRow.Cells("claimsend_dateout").Value.ToString())
If (deliveryDate - DateTime.Now).Days > 3 Then
MessageBox.Show("เช็คสี")
gridRow.DefaultCellStyle.BackColor = Color.Red
Else
MessageBox.Show("เช็ค Days" & (deliveryDate - DateTime.Now).Days )
End If
Next
End Sub
Private Sub AppliedStyleGrid()
For Each gridRow As DataGridViewRow In datagrid_bill.Rows
Dim deliveryDate As DateTime = Convert.ToDateTime(gridRow.Cells("claimsend_dateout").Value.ToString())
If (deliveryDate - DateTime.Now).Days > 3 Then
MessageBox.Show("เช็คสี")
gridRow.DefaultCellStyle.BackColor = Color.Red
Else
MessageBox.Show("เช็ค Days " & deliveryDate & " Def = " & (deliveryDate - DateTime.Now).Days )
End If
Next
End Sub
select *, Datediff(day,Startdate,Enddate) as Waranty--เอา Columnนี้ไป check From table --ทำDatediff ในนี้
Code (VB.NET)
dim objConn as new sqlconnection
dim DA as new sqldataAtapter
dim DT as new Datatable
dim sqltem as string
dim strConn as string = "server=host;database=db;trusted_connection=true;"
page_load
rangeWaranty()
MyDatagrid ()
end sub
private sub MyDatagrid 'อันนี้เขียนสดนะครับผิดพลาด ขอ อภัยครับ พอดีลืมเอา notebook มา
using objConn as new sqlconnect(strconn)
objConn.open
sqltem = "select *, Datediff(day,Startdate(column),Enddate(column)) as Waranty From table"
using DA as new sqldataAdapter
DT = New DATAtable
DA.Fill(DT)
DataGridView1.datasource = DT
end using
end sub
private sub rangeWaranty()
For i As Integer = 0 To DataGridView1.RowCount - 1
If Convert.ToInt16(DataGridView1(2, i).Value) < 3 Then
DataGridView1(2, i).Style.BackColor = Color.Red
End If
Next
Private Sub AppliedStyleGrid()
For Each gridRow As DataGridViewRow In datagrid_bill.Rows
Dim deliveryDate As DateTime = Convert.ToDateTime(gridRow.Cells("claimsend_dateout").Value.ToString())
If (DateTime.Now - deliveryDate).Days > 7 Then
gridRow.DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub
Private Sub AppliedStyleGrid()
For Each gridRow As DataGridViewRow In datagrid_bill.Rows
Dim deliveryDate As DateTime = Convert.ToDateTime(gridRow.Cells("claimsend_dateout").Value.ToString())
If (DateTime.Now - deliveryDate).Days > 7 Then
gridRow.DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub
หน้าฟร์อมเมนมีแค่นี้ครับอาจารย์
Private Sub ToolStripButton1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menu_cutbill.Click
frm_cutbillnew.Show()
frm_cutbillnew.MdiParent = Me
End Sub
Private Sub dataGridView1_DataBindingComplete(ByVal sender As Object, _
ByVal e As DataGridViewBindingCompleteEventArgs) _
Handles dataGridView1.DataBindingComplete
MessageBox.Show("เช็ค dataGridView ")
End Sub
ไม่ต่างกันเลยครับอาจารย์ เกรงใจอาจารย์จังเลยครับ แต่อาจารย์ช่วยผมก่อนนะครับ ขอบคุณอาจารย์นะครับ รันบนฟร์อมเมนกด ok 3 รอบ
รันเดี่ยวกด ok 2 รอบครับอาจารย์
Private Sub datagrid_bill_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles datagrid_bill.DataBindingComplete
MessageBox.Show("เช็ค dataGridView ")
End Sub
Private Sub datagrid_bill_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles datagrid_bill.DataBindingComplete
For Each gridRow As DataGridViewRow In datagrid_bill.Rows
Dim deliveryDate As DateTime = Convert.ToDateTime(gridRow.Cells("claimsend_dateout").Value.ToString())
If (DateTime.Now - deliveryDate).Days > 7 Then
gridRow.DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub