private void radGridView1_DataError(object sender, GridViewDataErrorEventArgs e){ e.Cancel = false; if ((e.Exception) is System.Data.NoNullAllowedException) { RadGridView view = (RadGridView)sender; if (view.CurrentRow is GridViewNewRowInfo) { view.CurrentRow.ErrorText = e.Exception.Message; //The following line doesnt work when adding a row, as e.RowIndex will equal -1
//(sender as RadGridView).Rows[e.RowIndex].ErrorText = e.Exception.Message; e.ThrowException = false; } }}I could use a little help if you can. I am new to Telerik and a relatively new programmer, so please bear with me as I try to explain my goal.
Essentially what I am trying to do is pivot records from a "View" in my database to produce a full year calendar using a radGridView as the container for the output. The radGridView is bound to a seperate SQL Server table. There are 12 records in the table and 33 columns.This table is only used as a template for the radGridView so all fields are null except for the two where I have set the month name and month #. The radGridView is to be used for visualization only and is not meant to allow for direct editing of records. The table I am using for the template has;
* 12 rows
- One row for each month ( RowIndex + 1 = month of the year)
* 33 Columns
- One column for the name of the month ( .ColumnIndex 0)
- One column for each possible day of the month ( .ColumnIndex 1 - 31). The day columns are named 1, 2, ..... ,31
- The last column in the grid ( .ColumnIndex 32) has the month number. Used for sorting only.
What I am trying to do is;
The "View" I am querying has 6 columns; GPID, AttDate, aDay, aMonth, aYear, Incidents
The following code works except that it sets each cell value in the columns to the first matching record it finds in the database.
Private Sub radGridView1_CellFormatting() Dim selectedIndex As Integer = Me.RadGridView1.Rows.IndexOf(Me.RadGridView1.CurrentRow) Dim selectedcolumn As Integer = Me.RadGridView1.CurrentCell.ColumnIndex Dim EE As Integer Dim vbDay As Integer 'Day of the month, also the name of the column Dim vbMonth As Integer ' Month of the year, also row index + 1 Dim vbYear As Integer 'Year being generated EE = CInt(TextBox1.Text) ' Employee id # vbYear = CInt(TextBox2.Text) 'Year for calendar For Each row As GridViewDataRowInfo In RadGridView1.Rows If Me.RadGridView1.CurrentCell.ColumnIndex > 0 and Me.RadGridView1.CurrentCell.ColumnIndex < 32 Then vbDay = selectedcolumn vbMonth = selectedIndex + 1 row.Cells("1").Value = GetEntry(EE, vbDay, vbMonth, vbYear) 'Testing with only a couple of columns. row.Cells("2").Value = GetEntry(EE, vbDay, vbMonth, vbYear)
' ......
End If Next End Sub Public Function GetEntry(ByVal EE As Integer, ByVal vbDay As Integer, ByVal vbMonth As Integer, ByVal vbYear As Integer) Dim CalEntry As String Dim connstring As String = ("Data Source=MyComputer\SQLEXPRESS;Initial Catalog=MAPPSQL;Persist Security Info=True;User ID=myuser;Password=mypass") Dim SelectSQLInc As String = ("Select Incidents From View_AttCombined Where (GPID like '" & EE & "') and (aDay like '" & vbDay & "') and (aMonth like '" & vbMonth & "')and (aYear like '" & vbYear & "')") Dim MySDA As New SqlDataAdapter Dim DBconn As New SqlConnection(connstring) Dim myCom As New SqlClient.SqlCommand(SelectSQLInc, DBconn) Dim MyDS As New DataSet DBconn.Open() MySDA.SelectCommand = myCom MySDA.Fill(MyDS) DBconn.Close() Try CalEntry = MyDS.Tables(0).Rows(0).Item(("Incidents").ToString) Catch ex As Exception CalEntry = "" 'Return nothing if no matching record is found. End Try Return CalEntry End Function
What would I change to loop through each cell one at the time and set the value to the value returned from GetEntry?
Thanks for the help. Let me know if I have totally confused you and need to clarify myself.
Imports Telerik.WinControls.UIPublic Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click i = 0 For Each oRow As GridViewDataRowInfo In RadGridView1.Rows() oRow.Cells(0).Tag = "" oRow.Cells(0).Value = 0 Next End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load CreateFormControls() Dim list As New ArrayList() Dim i As Integer = 0 While i < 55 list.Add(New ValueType(Of Integer)((i + 1))) ' System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) i += 1 End While Me.RadGridView1.DataSource = list End Sub Private Sub CreateFormControls() Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView() Me.Button1 = New System.Windows.Forms.Button() Me.Button2 = New System.Windows.Forms.Button() ' 'RadGridView1 ' Me.RadGridView1.Location = New System.Drawing.Point(13, 13) Me.RadGridView1.Name = "RadGridView1" Me.RadGridView1.Size = New System.Drawing.Size(267, 194) Me.RadGridView1.TabIndex = 0 Me.RadGridView1.Text = "RadGridView1" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(13, 213) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(252, 23) Me.Button1.TabIndex = 1 Me.Button1.Text = "Refresh Viewable Cells...Make other cell stale" Me.Button1.UseVisualStyleBackColor = True ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(12, 242) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(136, 23) Me.Button2.TabIndex = 1 Me.Button2.Text = "Total Data Updates" Me.Button2.UseVisualStyleBackColor = True ' 'Form1 ' Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.RadGridView1) End Sub Public Class ValueType(Of T) Private item As T Public Sub New() End Sub Public Sub New(ByVal item As T) Me.item = item End Sub Public Property ItemProperty() As T Get Return Me.item End Get Set(ByVal value As T) Me.item = value End Set End Property End Class Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting If e.ColumnIndex = 0 Then If e.Row.Cells(0).Tag <> "UPDATED" Then e.CellElement.Value = Now.Second e.Row.Cells(0).Tag = "UPDATED" i += 1 End If End If End Sub Dim i As Integer Private Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click MsgBox("Date Update Called " & i & " times") End SubEnd Class
rgvResults.MasterTemplate.EnableFiltering = TrueDim filter As New FilterDescriptor()filter.PropertyName = "attrib_exists"filter.[Operator] = FilterOperator.IsEqualTofilter.Value = "Y"filter.IsFilterEditor = TruergvResults.MasterTemplate.FilterDescriptors.Add(filter)rgvResults.MasterTemplate.Columns("attrib_exists").FilterDescriptor = filterrgvResults.MasterTemplate.Refresh()