DataGridView summary on Footer Vb.Net
Imports System.Drawing
Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim total As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim adapter As New SqlDataAdapter()
Dim ds As New DataSet()
Dim i As Integer = 0
Dim sql As String = Nothing
Dim connetionString As String = "Data Source=.;Initial Catalog=pubs;User ID=sa;Password=*****"
sql = "select top 6 ord_num,stor_id,title_id,payterms,qty from sales"
Dim connection As New SqlConnection(connetionString)
connection.Open()
Dim command As New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
adapter.Dispose()
command.Dispose()
connection.Close()
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lblqy As Label = DirectCast(e.Row.FindControl("lblqty"), Label)
Dim qty As Integer = Int32.Parse(lblqy.Text)
total = total + qty
End If
If e.Row.RowType = DataControlRowType.Footer Then
Dim lblTotalqty As Label = DirectCast(e.Row.FindControl("lblTotalqty"), Label)
lblTotalqty.Text = total.ToString()
End If
End Sub
End Class
DataGridView cell move Vb.Net
If e.KeyCode = Keys.Enter Then
Select Case DataGridView1.CurrentCell.ColumnIndex
Case 1
If Len(Trim(DataGridView1.CurrentRow.Cells(1).Value)) > 0 Then
DataGridView1.CurrentCell = DataGridView1(2, DataGridView1.CurrentCell.RowIndex)
DataGridView1.Focus()
Else
DataGridView1.CurrentCell = DataGridView1(3, DataGridView1.CurrentCell.RowIndex)
End If
Case 2
DataGridView1.CurrentCell = DataGridView1(3, DataGridView1.CurrentCell.RowIndex)
Case 3
DataGridView1.CurrentCell = DataGridView1(4, DataGridView1.CurrentCell.RowIndex)
Case 4
DataGridView1.CurrentCell = DataGridView1(5, DataGridView1.CurrentCell.RowIndex)
Case 5
DataGridView1.CurrentCell = DataGridView1(1, DataGridView1.CurrentCell.RowIndex + 1)
End Select
End If
e.Handled = True
DataGridView Cell Color Vb.Net
DataGridView1.GridColor = Color.Red
DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None
DataGridView1.BackgroundColor = Color.LightGray
DataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red
DataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow
DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.[True]
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.AllowUserToResizeColumns = False
DataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige