|
-
Feb 11th, 2019, 10:43 AM
#7
Re: Simple Row Counter SQL?
 Originally Posted by ChrisE
well I don't know the Kendo Grid.
this is what I use for the DGV, it adds a Linenumber
see if you can't adapt it to the Kendo Grid
Code:
Public Class Form1
Private mRandomClass As New Random()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtb As New System.Data.DataTable
dtb.Columns.Add("Column1", GetType(Integer))
dtb.Columns.Add("Column2", GetType(Double))
dtb.Columns.Add("Column3", GetType(Date))
dtb.Columns.Add("Column4", GetType(Decimal))
dtb.Columns.Add("Column5", GetType(Integer))
dtb.Columns.Add("Column6", GetType(Integer))
For i As Integer = 0 To 10
Dim Zahl As Double = mRandomClass.Next(100, 10000000)
Dim Datum As Date = Date.Now.AddSeconds(Convert.ToDouble(mRandomClass.Next(1, 1000000)))
Dim Geld As Decimal = mRandomClass.Next(1, 100000000)
dtb.LoadDataRow(New Object() {1 + i, _
Zahl.ToString("#,##0.00"), _
Datum.ToString("dd.MM.yyyy HH:mm:ss"), _
Geld.ToString("#,##0.00"), _
mRandomClass.Next, _
mRandomClass.Next}, _
True)
Next
Dim dvw As DataView = dtb.DefaultView
dvw.Sort = "Column3 ASC"
Dim dtbSorted As DataTable = dvw.ToTable()
DataGridView1.DataSource = dtbSorted
Me.DataGridView1.Columns(4).DefaultCellStyle.Format = "c"
End Sub
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
RownumberToHeader(CType(sender, DataGridView), e, Color.Brown)
End Sub
Public Sub RownumberToHeader(ByVal dgv As DataGridView, _
ByVal e As DataGridViewCellPaintingEventArgs, _
Optional ByVal nColor As Object = Nothing, _
Optional ByVal lastRowOnly As Boolean = False, _
Optional ByVal selRowOnly As Boolean = False)
Dim d As New Date
Dim w As Boolean, numColor As Color, dFont As Font
With dgv
If .RowCount < 2 Then Exit Sub
Dim font As Font = .RowHeadersDefaultCellStyle.Font
dFont = New Font(font.FontFamily, font.Size, FontStyle.Bold)
Dim rc As String = Format(.RowCount, " #,##0")
Dim maxSize As SizeF = New SizeF(TextRenderer.MeasureText(rc, dFont).Width, _
TextRenderer.MeasureText(rc, dFont).Height)
.RowHeadersWidth = CInt(maxSize.Width + 25)
numColor = .RowHeadersDefaultCellStyle.ForeColor
If nColor IsNot Nothing Then numColor = CType(nColor, Color)
Dim k As Short = CShort(IIf(.AllowUserToAddRows = True, 2, 1))
Dim ri As Integer = 0
w = (e.ColumnIndex = -1 And e.RowIndex >= ri)
If lastRowOnly Then
ri = .RowCount - k
w = (e.ColumnIndex = -1 And e.RowIndex >= ri)
ElseIf selRowOnly And dgv.SelectedRows.Count > 0 Then
ri = .SelectedRows(0).Index
w = (e.ColumnIndex = -1 And e.RowIndex = ri)
End If
End With
If w Then
If dgv.Rows(e.RowIndex).IsNewRow = False Then
With e
Dim rowStr As String = Format(.RowIndex + 1, " #,##0")
Dim StringSize As SizeF = New SizeF( _
TextRenderer.MeasureText(rowStr, dFont).Width, _
TextRenderer.MeasureText(rowStr, dFont).Height)
.PaintBackground(.ClipBounds, False)
.PaintContent(.ClipBounds)
Using brush As New SolidBrush(numColor)
.Graphics.DrawString((rowStr).ToString, dFont, brush, _
.CellBounds.Right - StringSize.Width, _
.CellBounds.Top + (.CellBounds.Height - StringSize.Height) / 2)
End Using
.Handled = True
End With
End If
End If
End Sub
HTH
Thanks Chris but its an asp.net mvc website with the telerik/kendo grid which renders different than a winforms grid. It calls the controller method I posted to get its datasource at the client level
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|