Saturday, February 3, 2018

Datagridview sort

How to clear Datagridview

There is two ways to clear rows in datagridview :



1- When the datagridview is not assigned to Datasource :


            DataGridView1.Rows.Clear()



2- When the datagridview isassigned to Datasource :



           DataGridView1.DataSource = Nothing
           DataGridView1.DataMember = Nothing
           DataGridView1.Refresh()
 

 

Thursday, February 1, 2018

Print Datagridview





çi dessous le code complet :

Imports System
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing

Public Class Form1

Private strFormat As StringFormat
Private arrColumnLefts As New ArrayList
Private arrColumnWidths As New ArrayList
Private iCellHeight As Integer = 0
Private iTotalWidth As Integer = 0
Private iRow As Integer = 0
Private bFirstPage As Boolean = False
Private bNewPage As Boolean = False
Private iHeaderHeight As Integer = 0

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.Rows.Add("0", "Iheb", "32", "IT Manager", "Tunisia")
DataGridView1.Rows.Add("1", "Sam", "32", "Teacher", "USA")
DataGridView1.Rows.Add("2", "Jhon", "22", "Student", "Philippine")
DataGridView1.Rows.Add("3", "David", "25", "Student", "UK")
End Sub

Private Sub printDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint

Try

strFormat = New StringFormat
strFormat.Alignment = StringAlignment.Near
strFormat.LineAlignment = StringAlignment.Center
strFormat.Trimming = StringTrimming.EllipsisCharacter