Telerik Forums
UI for WinForms Forum
2 answers
97 views
How do you enable the Close Button only for certain tabs?
n/a
Top achievements
Rank 1
Veteran
 answered on 12 Jan 2021
3 answers
89 views

Hi, I was wondering how I could specify my own images (from my project resource file) for the buttons in a vertical track bar. Is this possible? if so how?

I probably need to do this at run-time due as the user is able to change themes which I suspect will cause things to go wrong.

 

Regards

Toby

 

Nadya | Tech Support Engineer
Telerik team
 answered on 08 Jan 2021
4 answers
126 views

I have a grid bound to a collection of objects and i want to have a custom editor for a column. I followed most of the example here:

https://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells

I want to have 2 editors in this cell, one for manual entry and one with a dropdown of values. I have it mostly working, the editors show up during edit mode, the value on the underlying object is correct, but it doesn't show up in the grid for that column. The column is blank. Here is the code.

 

Imports System.ComponentModel
Imports Telerik.WinControls
Imports Telerik.WinControls.UI
 
Public Class test1
    Inherits System.Windows.Forms.Form
 
    'moved designer here for forum post
#Region " Designer "
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Dim GridViewTextBoxColumn1 As Telerik.WinControls.UI.GridViewTextBoxColumn = New Telerik.WinControls.UI.GridViewTextBoxColumn()
        Dim GridViewDecimalColumn1 As Telerik.WinControls.UI.GridViewDecimalColumn = New Telerik.WinControls.UI.GridViewDecimalColumn()
        Dim GridViewDecimalColumn2 As Telerik.WinControls.UI.GridViewDecimalColumn = New Telerik.WinControls.UI.GridViewDecimalColumn()
        Dim GridViewDecimalColumn3 As DropdownandSpinEditorColumn = New DropdownandSpinEditorColumn()
        Dim TableViewDefinition1 As Telerik.WinControls.UI.TableViewDefinition = New Telerik.WinControls.UI.TableViewDefinition()
        Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView()
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'RadGridView1
        '
        Me.RadGridView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.RadGridView1.Location = New System.Drawing.Point(0, 0)
        '
        '
        '
        GridViewTextBoxColumn1.FieldName = "Id"
        GridViewTextBoxColumn1.HeaderText = "Id"
        GridViewTextBoxColumn1.Name = "Id"
        GridViewTextBoxColumn1.Width = 150
        GridViewDecimalColumn1.DecimalPlaces = 0
        GridViewDecimalColumn1.FieldName = "SpecialNumber1"
        GridViewDecimalColumn1.HeaderText = "Special 1"
        GridViewDecimalColumn1.Name = "SpecialNumber1"
        GridViewDecimalColumn1.Width = 150
        GridViewDecimalColumn2.DecimalPlaces = 0
        GridViewDecimalColumn2.FieldName = "SpecialNumber2"
        GridViewDecimalColumn2.HeaderText = "Special 2"
        GridViewDecimalColumn2.Name = "SpecialNumber2"
        GridViewDecimalColumn2.Width = 150
        GridViewDecimalColumn3.DecimalPlaces = 0
        GridViewDecimalColumn3.FieldName = "ActionNumber"
        GridViewDecimalColumn3.HeaderText = "Action Number"
        GridViewDecimalColumn3.Name = "ActionNumber"
        GridViewDecimalColumn3.Width = 200
        Me.RadGridView1.MasterTemplate.Columns.AddRange(New Telerik.WinControls.UI.GridViewDataColumn() {GridViewTextBoxColumn1, GridViewDecimalColumn1, GridViewDecimalColumn2, GridViewDecimalColumn3})
        Me.RadGridView1.MasterTemplate.ViewDefinition = TableViewDefinition1
        Me.RadGridView1.Name = "RadGridView1"
        Me.RadGridView1.Size = New System.Drawing.Size(800, 450)
        Me.RadGridView1.TabIndex = 0
        '
        'test1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(800, 450)
        Me.Controls.Add(Me.RadGridView1)
        Me.Name = "test1"
        Me.Text = "test1"
        CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
 
    End Sub
 
    Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView
#End Region
 
    Private _list As New BindingList(Of GenData)
 
    Private Sub test1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim r As New Random(Now.Millisecond)
        For i = 100 To 110
            _list.Add(New GenData(r) With {.ActionNumber = i})
        Next
        Me.RadGridView1.DataSource = _list
    End Sub
 
    Private Sub RadGridView1_CreateCell(sender As Object, e As GridViewCreateCellEventArgs) Handles RadGridView1.CreateCell
        If TypeOf e.Row.RowInfo Is GridViewDataRowInfo Then
            Select Case e.Column.Name.ToLower()
                Case "actionnumber"
                    e.CellElement = New DropdownandSpinEditorCellElement(e.Column, e.Row)
                    e.CellType = GetType(DropdownandSpinEditorCellElement)
 
            End Select
        End If
    End Sub
 
    Private Sub RadGridView1_CellEndEdit(sender As Object, e As GridViewCellEventArgs) Handles RadGridView1.CellEndEdit
        If TypeOf e.Row Is GridViewDataRowInfo Then
            Dim elementsToRemove As New List(Of RadElement)
            Dim d = e.Row.DataBoundItem
            Console.WriteLine("end edit - " + d.ToString())
            Select Case e.Column.Name.ToLower()
                Case "actionnumber"
                    For Each c In RadGridView1.CurrentCell.Children
                        If TypeOf c Is RadDropDownListElement Then
                            elementsToRemove.Add(c)
                        End If
                    Next
                    For Each i In elementsToRemove
                        RadGridView1.CurrentCell.Children.Remove(i)
                        Console.WriteLine("end edit : removed dropdown")
                    Next
            End Select
        End If
    End Sub
 
    Private Sub RadGridView1_CellBeginEdit(sender As Object, e As GridViewCellCancelEventArgs) Handles RadGridView1.CellBeginEdit
        If TypeOf e.Row Is GridViewDataRowInfo Then
            Dim d = e.Row.DataBoundItem
            Console.WriteLine("begin edit - " + d.ToString())
            Select Case e.Column.Name.ToLower()
                Case "actionnumber"
                    CType(RadGridView1.CurrentCell, DropdownandSpinEditorCellElement).DrawEditor(d)
            End Select
        End If
    End Sub
End Class
 
Public Class GenData
    Private _rand As Random
 
    Public Sub New()
        _rand = New Random(Date.Now.Millisecond)
        SetSpecials()
    End Sub
    Public Sub New(rand As Random)
        _rand = rand
        SetSpecials()
    End Sub
    Public Sub SetSpecials()
        SpecialNumber1 = _rand.Next()
        SpecialNumber2 = _rand.Next()
    End Sub
    Public Overrides Function ToString() As String
        Return NameOf(Id) + " - " + Id + ", " + NameOf(ActionNumber) + " - " + ActionNumber.ToString()
    End Function
    Public Property Id As String = Guid.NewGuid.ToString
    Public Property SpecialNumber1 As Integer = -1
    Public Property SpecialNumber2 As Integer = -1
    Public Property ActionNumber As Integer = -1
End Class
 
Public Class DropdownandSpinEditorCellElement
    Inherits GridDataCellElement
 
    Private _radDropDownElement As RadDropDownListElement
 
    Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement)
        MyBase.New(column, row)
    End Sub
 
    Public Sub DrawEditor(d As GenData)
        _radDropDownElement = BuildDropdown(d)
        Me.Children.Add(_radDropDownElement)
        AddHandler _radDropDownElement.SelectedIndexChanged, AddressOf HandleSelectChanged
    End Sub
 
    Protected Overrides Sub CreateChildElements()
        MyBase.CreateChildElements()
    End Sub
 
    Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
        Get
            Return GetType(GridDataCellElement)
        End Get
    End Property
    Public Overrides Function IsCompatible(ByVal data As GridViewColumn, ByVal context As Object) As Boolean
        Return TypeOf data Is GridViewDecimalColumn AndAlso TypeOf context Is GridDataRowElement
    End Function
 
    Protected Overrides Function ArrangeOverride(ByVal finalSize As SizeF) As SizeF
        Console.WriteLine("children count was : " + Me.Children.Count.ToString)
        If Me.Children.Count = 2 Then
            Dim dropDownWidth As Single = finalSize.Width * 0.5
            Dim dropDownRect As New RectangleF(0, 0, dropDownWidth - 1, finalSize.Height)
            Dim spinEditorRect As New RectangleF(dropDownWidth + 1, 0, finalSize.Width - dropDownWidth - 2, finalSize.Height)
            Me.Children(0).MinSize = New Size(dropDownWidth - 2, 20)
            Me.Children(0).Arrange(dropDownRect)
            Me.Children(1).Arrange(spinEditorRect)
        End If
        Return finalSize
    End Function
 
    Private Function BuildDropdown(ByRef d As GenData) As RadDropDownListElement
        Dim speedDropdown As New RadDropDownListElement()
        speedDropdown.MinSize = New Size(40, 20)
        speedDropdown.MaxSize = speedDropdown.MinSize
        speedDropdown.DropDownWidth = 150
        speedDropdown.DropDownHeight = 130
        speedDropdown.Padding = New Padding(2, 2, 2, 2)
        speedDropdown.Tag = d
        speedDropdown.DataSource = BuildSpecialList(d)
        speedDropdown.DisplayMember = "DisplayValue"
        speedDropdown.ValueMember = "Value"
        speedDropdown.SelectedIndex = 0
        Return speedDropdown
    End Function
 
    Private Sub HandleSelectChanged(sender As Object, e As Data.PositionChangedEventArgs)
        Dim speedDropdown As RadDropDownListElement = CType(sender, RadDropDownListElement)
        Dim d As GenData = speedDropdown.Tag
        Dim data As GenericItem(Of Double) = speedDropdown.SelectedItem.DataBoundItem
        d.ActionNumber = data.Value
    End Sub
 
    Private Function BuildSpecialList(d As GenData) As List(Of GenericItem(Of Double))
        Dim l As New List(Of GenericItem(Of Double))
        Dim g As New GenericItem(Of Double)
        g.DisplayValue = ""
        g.Value = -1
        l.Add(g)
        g = New GenericItem(Of Double)
        g.DisplayValue = d.SpecialNumber1.ToString
        g.Value = d.SpecialNumber1
        l.Add(g)
        g = New GenericItem(Of Double)
        g.DisplayValue = d.SpecialNumber2.ToString
        g.Value = d.SpecialNumber2
        l.Add(g)
        Return l
    End Function
End Class
 
Public Class DropdownandSpinEditorColumn
    Inherits GridViewDecimalColumn
    Public Sub New(ByVal fieldName As String)
        MyBase.New(fieldName)
    End Sub
    Public Sub New()
        MyBase.New()
    End Sub
    Public Overrides Function GetCellType(ByVal row As GridViewRowInfo) As Type
        If TypeOf row Is GridViewDataRowInfo Then
            Return GetType(DropdownandSpinEditorCellElement)
        End If
        Return MyBase.GetCellType(row)
    End Function
End Class
 
Public Class GenericItem(Of ValueType)
    Public Property DisplayValue As String = ""
    Public Property Value As ValueType
    Public Property Data As Object = Nothing
End Class
dd
Top achievements
Rank 1
 answered on 07 Jan 2021
3 answers
297 views

How to add a context menu by pressing a RadButton?

ContextMenuStrip mainMenu = new ContextMenuStrip();
RadButtonElement btn = new RadButtonElement();
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 07 Jan 2021
1 answer
117 views

Hello,

I have a GridView with GroupComparer and it works fine, but if I add EnableCustomSorting true, the GroupComparer stops working, it's not called by GridView anymore. Could you please advise how to make it work together.

 

public Form1()
{
  InitializeComponent();
 
  DataTable dt = new DataTable();
  dt.Columns.Add( "A", typeof( string ) );
 
  this.radGridView1.Columns.Add( "A" );
  this.radGridView1.Columns.Add( "B" );
 
  this.radGridView1.Rows.Add( "1", "1");
  this.radGridView1.Rows.Add( "2", "2" );
  this.radGridView1.Rows.Add( "10", "10" );
 
  this.radGridView1.MasterTemplate.GroupComparer = new GroupComparer();
 
  this.radGridView1.CustomSorting += RadGridView1_CustomSorting;
  this.radGridView1.EnableCustomSorting = true; //if true, GroupComparer stop working
}
 
private void RadGridView1_CustomSorting( object sender, GridViewCustomSortingEventArgs e )
{
  //logic to sort columns.
}
 
public class GroupComparer : IComparer<Group<GridViewRowInfo>>
{
  public int Compare( Group<GridViewRowInfo> x, Group<GridViewRowInfo> y )
  {
    int parsedX;
    int parsedY;
    if ( int.TryParse( ( (object[])x.Key ).First().ToString(), out parsedX ) &&
        int.TryParse( ( (object[])y.Key ).First().ToString(), out parsedY ) )
    {
      int result = parsedX.CompareTo( parsedY );
      DataGroup xGroup = x as DataGroup;
      if ( xGroup != null && ( (DataGroup)x ).GroupDescriptor.GroupNames.First().Direction == ListSortDirection.Descending )
      {
        result *= -1;
      }
      return result;
    }
    return ( (object[])x.Key )[0].ToString().CompareTo( ( (object[])y.Key )[0].ToString() );
  }
}
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 07 Jan 2021
1 answer
64 views

As title. Followed as my code and screen shot as attachment.

public partial class Form3 : Form
{
    public Form3()
    {
        this.InitializeComponent();
 
        this.label1.Text = this.radHScrollBar1.Minimum.ToString();
        this.label2.Text = this.radHScrollBar1.Maximum.ToString();
    }
 
    private void button1_Click(object sender, System.EventArgs e)
    {
        this.textBox1.Text = this.radHScrollBar1.Value.ToString();
    }
}
Nadya | Tech Support Engineer
Telerik team
 answered on 06 Jan 2021
4 answers
395 views
How do I allow only one row in a hierarchical RadGridView to expand at a time?
Nadya | Tech Support Engineer
Telerik team
 answered on 06 Jan 2021
2 answers
89 views

As title.

My xaxis is DateTimeCategoricalAxis and how to use ScatterSeries?

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 06 Jan 2021
1 answer
111 views

         i would like to drag RadTreeView Node to  winform standard Panel, but when i drag and drop  to the panel , my mouse always busying

         my code as fellows 

         

          panel   is   System.Windows.Forms.Panel panel

           this.tree  is  RadTreeView

 

           this.panel.AllowDrop = true;
            this.tree.AllowDrop = true;
           

            this.tree.ItemDrag  += Tree_ItemDrag;
            this.tree.DragEnter += new DragEventHandler(this.tree_FunctionList_DragEnter);

            this.panel.DragEnter += Panel_DragEnter;
            this.panel.DragDrop  += Panel_DragDrop;

 

        private void Tree_ItemDrag(object sender, RadTreeViewEventArgs e)
        {
            RadTreeNode tn = e.Node as RadTreeNode;
            if (tn != null)
            {
                (this.tree).DoDragDrop(tn, DragDropEffects.Copy);
            }
        }

        private void tree_FunctionList_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }



        private void Panel_DragDrop(object sender, DragEventArgs e)
        {
            RadTreeNode node = e.Data.GetData(typeof(RadTreeNode)) as RadTreeNode;
            Console.WriteLine(node.Text);
        }

        private void Panel_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 06 Jan 2021
10 answers
356 views
I'm using RadControls for WinForms 2008.3 1321.

I built an application, using a RadForm as main form. If I run it on a local computer everything looks good. But if I connect a remote computer via terminal services (remote desktop / RDP protocoll) which is running a "XP based" operating system (e.g. Windows XP oder Windows Server 2003) there is an issue:

The caption bar of the RadForm won't get drawn correctly. It is invisible, most time completely, sometimes just the left part (the one with the image). But it is there, obviously: if I click on the right place of the "invisible" caption bar I'm able to drag, minimize or close the window although I don't see the system menu buttons nor the whole bar itself. If I move the window outside the visible bounds of the screen and back to screen again the caption bar gets drawn correctly, with all images, titles, buttons and so on. But if I minimize/restore the window after this the drawing problems appear again.

As I said above the issue seems to occure only on XP based remote systems. On computers running a Vista derivative (like any Vista version or Windows Server 2008) the whole window gets drawn correctly. The problem is also independent from the RDP client. It occures the same if I use a XP station or a Vista station as client, which both have different RDP client versions. The RDP connection settings (as color depht oder performance settings) are also unimportant. Furthermore, only the caption bar of the form is affected but none of its contents (and I use a lot of RadControls in it), including main menu or status bar.

Can anybody confirm similar issues - and has a solution maybe?

Regards,
ReneMT
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 05 Jan 2021
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
ComboBox and ListBox (obsolete as of Q2 2010)
ListView
Chart (obsolete as of Q1 2013)
Form
PageView
MultiColumn ComboBox
TextBox
RichTextEditor
Menu
PropertyGrid
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
Rotator
TrackBar
MessageBox
SpinEditor
StatusStrip
CheckedListBox
Wizard
ShapedForm
SyntaxEditor
TextBoxControl
LayoutControl
CollapsiblePanel
Conversational UI, Chat
DateTimePicker
TabbedForm
CAB Enabling Kit
DataEntry
GroupBox
ScrollablePanel
WaitingBar
ScrollBar
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
ColorBox
Callout
FilterView
PictureBox
VirtualKeyboard
NavigationView
Accessibility
DataLayout
ToastNotificationManager
ValidationProvider
CalculatorDropDown
Localization
TimePicker
ButtonTextBox
FontDropDownList
Licensing
BreadCrumb
Security
LocalizationProvider
Dictionary
Overlay
Separator
SparkLine
TreeMap
StepProgressBar
SplashScreen
Flyout
ToolbarForm
NotifyIcon
Rating
TimeSpanPicker
BarcodeView
Calculator
OfficeNavigationBar
TaskbarButton
HeatMap
SlideView
PipsPager
AIPrompt
TaskDialog
+? more
Top users last month
Henri
Top achievements
Rank 2
Iron
Iron
Iron
SUNIL
Top achievements
Rank 2
Iron
Iron
Iron
David
Top achievements
Rank 1
Jackson
Top achievements
Rank 1
Iron
Iron
Tim
Top achievements
Rank 3
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Henri
Top achievements
Rank 2
Iron
Iron
Iron
SUNIL
Top achievements
Rank 2
Iron
Iron
Iron
David
Top achievements
Rank 1
Jackson
Top achievements
Rank 1
Iron
Iron
Tim
Top achievements
Rank 3
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?