Telerik Forums
UI for WinForms Forum
2 answers
1.1K+ views

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;

  • Loop through each cell where the column index is between 1 and 31;
  • Query a view in my database (There is a date field in the View where I have parted the day, month and year  from the date into seperate columns)
  • Return a record, if it exists, where
    • day =  .ColumnIndex
    • month = Rowindex + 1
    • Year = Textbox2.Text
    • GPID = Textbox1.Text
    • Set the Cell value to the string returned from the database

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.

 

Julian Benkov
Telerik team
 answered on 02 Aug 2011
1 answer
175 views
I thought I would contribute this proof of concept code I had to work out.  A single cell in a grid needed to update data via a call to a remote system.  However, if the grid had thousands of records, I did not want it to make thousands of remote calls on load.  So, I looked at the ViewCellFormatting event which allows me to retrieve the data only when the cell is visible.  

I also "cached" the data in the cell by setting its flag to "UPDATED".  The "Refresh Data" function actually loops through all rows, clears the cells' tags, and sets the value to zero.  When the visible cell's value is changed, the ViewCellFormatting event is fired and the remote call is made again.

In this proof of concept code, I am simply just updating the row to the current time's Second.  The first button refreshes the data and makes the other non-visible cell's stale by removing the tag.  

The second button will show the "i" count to prove the "remote" call is called only on the visible cells.

I tip my hat to Telerik for this pretty powerful and useful functionality!


Imports Telerik.WinControls.UI
 
 
 
Public 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 Sub
End Class

Stefan
Telerik team
 answered on 02 Aug 2011
1 answer
222 views
Hi,
I'm using a grid which is using a hierarchical view. I'm trying to apply a filter to one of the columns on the parent grid, which contains a simple Y/N character.

I've constructed the filter in the same way as I would on a simple grid view (on which it does what I ask of it) This is the code:

rgvResults.MasterTemplate.EnableFiltering = True
Dim filter As New FilterDescriptor()
filter.PropertyName = "attrib_exists"
filter.[Operator] = FilterOperator.IsEqualTo
filter.Value = "Y"
filter.IsFilterEditor = True
rgvResults.MasterTemplate.FilterDescriptors.Add(filter)
 
rgvResults.MasterTemplate.Columns("attrib_exists").FilterDescriptor = filter
rgvResults.MasterTemplate.Refresh()


The filter on the parent column appears on the grid and is populated once I apply the filter. However the data doesn't change. Infact, manually adjusting any of the column filters has no influence over the data at all.

Could someone please help me with where i'm going wrong? Like I said, on a simple grid, it works perfectly, I just cant get the parent/child grid to work correctly. I've spent the afternoon trying various things from example code but still no luck!

nb. the grid is bound to a datatable datasource.

Thanks in advance

Chris

Update: I fixed this by removing the grid from the form and adding a new one?! bizarre.
Julian Benkov
Telerik team
 answered on 02 Aug 2011
11 answers
183 views
Hi,

I like the demo of the rtb. The features in the demo would be absolutely fine for my purposes. The new rtb control seems to be a tiny part of the demo. I'd like to have the rtb with all formatting capabilities etc. as part of one drag and drop control with all the stripe commands (maybe configurable )etc.. Have I possibly overseen a fast way of configuring the rtb?  Or how could it be made as one single drag and drop tool?

I see that you have a wizard for quicksilver. Am I missing one?

Thank you,
Karl
Nikolay
Telerik team
 answered on 02 Aug 2011
1 answer
191 views
Hi,

In our HR system there are lot of situations, where we have to handle the structure of a company. The treeview is a possible solution, but that is not so impressive, like a real organizational chart.

On the web I have found these components, a similar control set would be nice to use in the Winforms environment.


Best regards,

Peter
Yavor
Telerik team
 answered on 02 Aug 2011
1 answer
124 views
I would like to show a stacked bar chart that is comprised of two series.  This part I have set up and working just fine using databinding.
There is always 24 points, one for each hour for both series.  I have set up the xaxis with shorttime and formatted the labels.  My datalayer is doing the oa date conversions and passing date values as double to the source datatable.  I'm handing the on_databind event to set up appropriate properties for the series including the col specifications and series type properies. 

Now that my range stacked bars are setup and working fine I am trying to add an additonal series to the chart that is not made up of a full 24 points.  In fact there may be 0 points or many points in the entire series landing on dates between the xaxis markers (which are formatted for each hour).  The reason for this is the third series is intended to represent events which for all intents and purposes are random.  I intended to use the same databinding event handler to capture and change the type to type point of this third series to point and simply append my data for this series to the existing datatable.  I would intended to pass the variable x dates of the third series with a static y value representing a value just above the max of my existing series1/2 stacked ranges.

and i was wondering if you could help me with a vb.net sample?

the series data looks something like this (assume in my data that I've done the oa_Date conversion). Further assume that for both series 1 and 2 there are full 24 points, one for each hour.

Whether I try to represent the dataset below using binding or manually creating series I can not get the position of the 3rd series set properly on the xaxis. 

series_1,5/5/2011 2:00,8
series_1,5/5/2011 3:00,9
series_1,5/5/2011 4:00,32
series_1,5/5/2011 5:00,3
 series_2,5/5/2011 2:00,21
series_2,5/5/2011 3:00,23
series_2,5/5/2011 4:00,3
series_2,5/5/2011 5:00,12
series_3,5/5/2011 2:23,30
series_3,5/5/2011 4:46,30
 
 

Peshito
Telerik team
 answered on 02 Aug 2011
2 answers
236 views
I am creating windows application with C# that requires to work with 2-3 users.The admin user should get
all the rights to access all forms and can do activity such as retreive data,insert, update and delete.wherein other
users should not get all the access.how do I disable controls that r updating data in database for other users.
can anyone brief me on this?
thanks in advance
erwin
Top achievements
Rank 1
Veteran
Iron
 answered on 01 Aug 2011
1 answer
397 views
hi, i have looked at the other posts regarding validation and your validation video. i do understand the row_validation and cell_validation events. However, in order to validate the entries AND mark the errors, i have to use the validation code twice which i dont want to do.  

My test code is shown below. Have also attached a screenshot.

Here's what i am trying to do:

in the grid2_RowValidating event i am validating and preventing user to go to next row. i would like to "mark/color" the cell with the error. I tried all the Style properties but only the forecolor works. (i have commented the lines not working)

So, in addition to RowValidating event, i decided to use the grid2_ViewCellFormatting event to validate and color the cell with the error.
This is working but i dont understand why i have to validate twice. (once in the RowValidating event to prevent them to go to the next row and again in the ViewCellFormatting event to "color" the cell) 

Am i doing something wrong? Why am i not able to set the Style Properties directly from within the RowValidating. I am using the Q2 2011 version (latest) 

Private Sub grid2_RowValidating(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.RowValidatingEventArgs) Handles grid2.RowValidating
    If TypeOf e.Row Is GridViewNewRowInfo Or TypeOf e.Row Is GridViewDataRowInfo Then
        If Not e.Row Is Nothing Then
                              
            Dim value As String = e.Row.Cells(1).Value
            If value > 10 Then
                e.Cancel = True
                e.Row.Cells(1).ErrorText = "cannot be greater than 10"
                e.Row.ErrorText = "cannot be greater than 10"
                e.Row.Cells(1).Style.ForeColor = Color.Red
                'These did not work so had to use the cell formating
                'e.Row.Cells(1).Style.DrawFill = True
                'e.Row.Cells(1).Style.NumberOfColors = 1
                'e.Row.Cells(1).Style.BackColor = Color.Peru
 
                'e.Row.Cells(1).Style.DrawBorder = True
                'e.Row.Cells(1).Style.BorderWidth = 2
            Else
                e.Row.ErrorText = String.Empty
            End If
        End If
    End If
 
 
End Sub
 
Private Sub grid2_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles grid2.ViewCellFormatting
    If grid2.IsInEditMode Then
 
        If TypeOf e.Row Is GridViewRowInfo Then
 
            Select Case e.ColumnIndex
                Case 1
                    e.CellElement.DrawFill = True
                    e.CellElement.NumberOfColors = 1
 
                    'validate again?? to set the coloring?
                    If e.CellElement.Value > 10 Then
                        'set visual clue
                        e.CellElement.BackColor = Color.Peru
                        e.CellElement.ForeColor = Color.Yellow
                        e.CellElement.Image = My.Resources._error
                    Else
                        'reset all
                        e.CellElement.BackColor = Color.White
                        e.CellElement.ForeColor = Color.Black
                        e.CellElement.Image = Nothing
                    End If
            End Select
 
        End If
    End If
End Sub
 
Jack
Telerik team
 answered on 01 Aug 2011
5 answers
255 views
I'm currently using a multiselect enabled dropdownlist.  How do I retreive the list of 'selected' items in the multiselect dropdownlist?

Thanks.
Jack
Telerik team
 answered on 01 Aug 2011
1 answer
71 views
I'm new to Telerik controls so I'm hopeful there maybe a solution to my problem but searching the documentation and forums I have yet to see it.

Problem
A typical usability problem with menus I frequently see is a menu or sub-menu (grouping of menu items beneath another menu) that instantly disappears if the user mouses over the wrong pixel while trying to mouse over to the menu item.  This can be frustrating causing the user to have to retrace their steps to once again reveal the menu and this time carefully tip-toe the mouse back through the narrow parameters allowed them so as not to trip the code just waiting to remove their destination.

Solution
This is a fairly simple problem technically which requires the library author to allow from some time delay before hiding the menu.  The logic would go something like (pseudo code):

OnMouseOverNonMenu
Start Timer

OnMouseOverMenu
     Stop Timer

OnTimerElapsed
      Hide menu
 

Summary
So far, I have not seen this solution being build into the Telerik menu though it seems like a perfect place for this solution.  Did I miss it? Is there a way to do this without me rolling my own menu control?

thanks,
Eric

Jack
Telerik team
 answered on 01 Aug 2011
Narrow your results
Selected tags
Tags
GridView
General Discussions
Scheduler and Reminder
Treeview
Dock
RibbonBar
Themes and Visual Style Builder
ChartView
Calendar, DateTimePicker, TimePicker and Clock
DropDownList
Buttons, RadioButton, CheckBox, etc
ListView
ComboBox and ListBox (obsolete as of Q2 2010)
Chart (obsolete as of Q1 2013)
Form
PageView
MultiColumn ComboBox
TextBox
RichTextEditor
PropertyGrid
Menu
RichTextBox (obsolete as of Q3 2014 SP1)
Panelbar (obsolete as of Q2 2010)
PivotGrid and PivotFieldList
Tabstrip (obsolete as of Q2 2010)
MaskedEditBox
CommandBar
PdfViewer and PdfViewerNavigator
ListControl
Carousel
Diagram, DiagramRibbonBar, DiagramToolBox
GanttView
Panorama
New Product Suggestions
Toolstrip (obsolete as of Q3 2010)
VirtualGrid
AutoCompleteBox
Label
Spreadsheet
ContextMenu
Panel
Visual Studio Extensions
TitleBar
Documentation
SplitContainer
Map
DesktopAlert
ProgressBar
CheckedDropDownList
TrackBar
MessageBox
Rotator
SpinEditor
StatusStrip
CheckedListBox
LayoutControl
SyntaxEditor
Wizard
ShapedForm
TextBoxControl
Conversational UI, Chat
DateTimePicker
CollapsiblePanel
TabbedForm
CAB Enabling Kit
GroupBox
DataEntry
ScrollablePanel
ScrollBar
WaitingBar
ImageEditor
Tools - VSB, Control Spy, Shape Editor
BrowseEditor
DataFilter
ColorDialog
FileDialogs
Gauges (RadialGauge, LinearGauge, BulletGraph)
ApplicationMenu
RangeSelector
CardView
WebCam
BindingNavigator
PopupEditor
RibbonForm
Styling
TaskBoard
Barcode
Callout
ColorBox
PictureBox
FilterView
Accessibility
VirtualKeyboard
NavigationView
DataLayout
ToastNotificationManager
ValidationProvider
CalculatorDropDown
Localization
TimePicker
ButtonTextBox
FontDropDownList
Licensing
BarcodeView
BreadCrumb
Security
LocalizationProvider
Dictionary
Overlay
Flyout
Separator
SparkLine
TreeMap
StepProgressBar
SplashScreen
ToolbarForm
NotifyIcon
DateOnlyPicker
Rating
TimeSpanPicker
Calculator
OfficeNavigationBar
TaskbarButton
HeatMap
SlideView
PipsPager
AIPrompt
TaskDialog
TimeOnlyPicker
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?