Telerik Forums
UI for WinForms Forum
7 answers
1.7K+ views

Hi everyone

I put a RadGridView in Form with enabled its edit mode (AllowEditRow = true), and has "id" and "name" columns, and three rows of data. Also I created a custom user control that has a TextBox and a Button (named it ccTest). Then I choose a cell from "name" column and any row at run time. Now I start to type letters from keyboard. In this case, I bring up the custom user control.

The problem is: The typed letters don't show in custom user control, because it's TextBox not focused yet. Therefore I must click one more time to focus it, before start type letters.

Question is: How can I focus the TextBox of custom user control when it appear from CellBeginEdit event?

Microsoft Visual Studio 2017 (C# language) installed on Windows 10  -  Telerik WinForms 2017 R3 SP1 (2017.3.1017.40).

-------------------------------------------

ccTest.Designer.cs:

namespace TestGridFocus
{
    partial class ccTest
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Component Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // textBox1
            //
            this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBox1.Location = new System.Drawing.Point(0, 0);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(92, 20);
            this.textBox1.TabIndex = 0;
            //
            // button1
            //
            this.button1.Dock = System.Windows.Forms.DockStyle.Right;
            this.button1.Location = new System.Drawing.Point(92, 0);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(28, 20);
            this.button1.TabIndex = 1;
            this.button1.Text = "?";
            this.button1.UseVisualStyleBackColor = true;
            //
            // ccTest
            //
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button1);
            this.Name = "ccTest";
            this.Size = new System.Drawing.Size(120, 20);
            this.ResumeLayout(false);
            this.PerformLayout();
 
        }
 
        #endregion
 
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button1;
    }
}

 

ccTest.cs:

using System.Windows.Forms;
 
namespace TestGridFocus
{
    public partial class ccTest : UserControl
    {
        public ccTest()
        {
            InitializeComponent();
        }
 
        public string Value
        {
            get
            {
                return textBox1.Text;
            }
            set
            {
                textBox1.Text = value;
            }
        }
    }
}

Form1.Designer.cs:

namespace TestGridFocus
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn1 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn2 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.TableViewDefinition tableViewDefinition1 = new Telerik.WinControls.UI.TableViewDefinition();
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).BeginInit();
            this.SuspendLayout();
            //
            // radGridView1
            //
            this.radGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.radGridView1.Location = new System.Drawing.Point(12, 12);
            //
            //
            //
            this.radGridView1.MasterTemplate.AllowAddNewRow = false;
            gridViewDecimalColumn1.FieldName = "id";
            gridViewDecimalColumn1.HeaderText = "id";
            gridViewDecimalColumn1.Name = "id";
            gridViewDecimalColumn1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
            gridViewTextBoxColumn1.FieldName = "name";
            gridViewTextBoxColumn1.HeaderText = "name";
            gridViewTextBoxColumn1.Name = "name";
            gridViewTextBoxColumn1.Width = 150;
            gridViewDecimalColumn2.FieldName = "age";
            gridViewDecimalColumn2.HeaderText = "age";
            gridViewDecimalColumn2.Name = "age";
            gridViewDecimalColumn2.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
            this.radGridView1.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] {
            gridViewDecimalColumn1,
            gridViewTextBoxColumn1,
            gridViewDecimalColumn2});
            this.radGridView1.MasterTemplate.ViewDefinition = tableViewDefinition1;
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(270, 237);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            this.radGridView1.CellBeginEdit += new Telerik.WinControls.UI.GridViewCellCancelEventHandler(this.radGridView1_CellBeginEdit);
            this.radGridView1.CellEndEdit += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellEndEdit);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(294, 261);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.RadGridView radGridView1;
    }
}

 

Form1.cs:

using System;
using System.Data;
using System.Windows.Forms;
using Telerik.WinControls;
 
namespace TestGridFocus
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private DataTable GetData()
        {
            DataTable dt = new DataTable();
 
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
 
            dt.Rows.Add(1, "Jack");
            dt.Rows.Add(2, "Joe");
            dt.Rows.Add(3, "Bob");
 
            dt.AcceptChanges();
 
            return dt;
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            radGridView1.DataSource = GetData();
        }
 
        ccTest test = new ccTest();
 
        private void radGridView1_CellBeginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)
        {
            if (e.Column == radGridView1.Columns["name"])
            {
                RadHostItem item = new RadHostItem(test);
 
                test.Value = e.Row.Cells[e.ColumnIndex].Value.ToString();
                radGridView1.CurrentCell.Children.Add(item);
                item.HostedControl.Focus();
            }
        }
 
        private void radGridView1_CellEndEdit(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (e.Column == radGridView1.Columns["name"])
            {
                e.Row.Cells[e.ColumnIndex].Value = test.Value;
                radGridView1.CurrentCell.Children.RemoveAt(0);
            }
        }
    }
}

 

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 04 Jun 2018
6 answers
457 views

How do I remove the white space above the grid columns?

I'm using the BusinessGrid theme and have looked everywhere trying to find how to remove this white space. It's at the very top of the grid above the header columns.

Thanks
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 04 Jun 2018
2 answers
617 views

How do I set the column width of Excel to auto fit or any fix width in Cell Formatting?  Thanks.

GridViewSpreadExport spreadExporter = new GridViewSpreadExport(gvInventory);
SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
spreadExporter.CellFormatting += SpreadExporter_CellFormatting;
spreadExporter.ExportCompleted += SpreadExporter_ExportCompleted;
spreadExporter.RunExport(OutputFilePath, exportRenderer);             

Bertha
Top achievements
Rank 1
 answered on 01 Jun 2018
2 answers
151 views

     RadBradCrumb is a nice idea, but seems to be not really finished.

First, there is no documentation at all.

This little page gives a hint, this thing exists, not more.

https://docs.telerik.com/devtools/winforms/treeview/breadcrumb

 

Second, the splitbuttons and the dropdownItems are nice initialized and working,

but the DefaultItem of the SplitButton is not set.

You cannot click on the Button, und go up the hierarchie, the most basic function of a breadcrumb.

You always have this dropdown-things only.

Additionally, the RadBradCrumb is quiet a Closed thing, there are no events to subscribe, no virtual methods to override, just nothing.

I have found a workaround for this, which makes it work es expected, but this should be default functionality.

public class BreadCrumbHandler
{
    private RadBreadCrumb crumb;
    public BreadCrumbHandler(RadBreadCrumb crumb)
    {
        this.crumb = crumb;
 
        // there is not other access to the DefaultItem of the SplitButtons in the BreadCrumb
        var r = crumb.RootElement.Children.First() as RadBreadCrumbElement;
        r.Items.ItemsChanged += BreadCrumb_ItemsChanged;
    }
 
    private void BreadCrumb_ItemsChanged(RadItemCollection changed, RadItem target, ItemsChangeOperation operation)
    {
        if (operation == ItemsChangeOperation.Inserted)
        {
            RadSplitButtonElement btn = target as RadSplitButtonElement;
            if (btn != null)
            {
                var defaultItem = new RadMenuItem(btn.Text);
                defaultItem.Text = btn.Text;
                defaultItem.Click += DefaultItem_Click;
                btn.DefaultItem = defaultItem;
            }
        }
        else if (operation == ItemsChangeOperation.Clearing)
        {
            foreach (var item in changed.OfType<RadSplitButtonElement>())
            {
                var menuItem = item.DefaultItem as RadMenuItem;
                if (menuItem != null)
                    menuItem.Click -= DefaultItem_Click;
                item.DefaultItem = null;
            }
        }
        else if (operation == ItemsChangeOperation.Removing)
        {
            RadSplitButtonElement btn = target as RadSplitButtonElement;
            if (btn != null)
            {
                var menuItem = btn.DefaultItem as RadMenuItem;
                if (menuItem != null)
                    menuItem.Click -= DefaultItem_Click;
                btn.DefaultItem = null;
            }
        }
    }
 
    private void DefaultItem_Click(object sender, EventArgs e)
    {
        var menuItem = (RadMenuItem)sender;
        var currentNode = crumb.DefaultTreeView.SelectedNode;
        while (currentNode != null)
        {
            if (currentNode.Text == menuItem.Text) // not really safe test, but works as long as Texts are distinct
            {
                crumb.DefaultTreeView.SelectedNode = currentNode;
                return;
            }
            currentNode = currentNode.Parent;
        }
    }
}

 

 

 

 

Hristo
Telerik team
 answered on 01 Jun 2018
1 answer
715 views

How to do paging with load on demand with radgridview in WinForm?

I have downloaded the demo of winform from Telerik.  But the left starting part of source code is cut off.  I am using Windows 7. Pressing left arrow did not go to the leftmost part (attached screen shot).

Where can I downloaded the source code of demo of winform?

Dimitar
Telerik team
 answered on 01 Jun 2018
3 answers
175 views
Hello I have a problem once I'm in the Grid.MasterView.TableAddNewRow row there is no way out of this ESC and it does not leave this row, is there any way to leave this row if the user does not want to add anything? is a problem in the version of 2015 did not have this problem assumes that the version 2017 was going to be improved but has many problems
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 31 May 2018
1 answer
123 views

I'm using column groups.  Users can rearrange columns but i would like to prevent them from dragging columns to another group.

Thanks,

John

 

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 30 May 2018
6 answers
528 views
Hi I have problems with the UserAddingRow event, in the child levels of the main if the property e.cancel = True does not let me leave the grid editor, even if I cancel the edition I can not leave the grid row editor, could someone help me thanks beforehand
Daniel
Top achievements
Rank 1
 answered on 30 May 2018
11 answers
362 views

Hi all

I need custom position checkbox the same in picture. All Checkbox at Left.

[-]  >A

[-]    >B

[-]         >C

 

Dimitar
Telerik team
 answered on 30 May 2018
2 answers
295 views

Hello,

I have been having trouble determining where I can locate and remove the dashed border on RadButtons.  I believe it is the focus border, but I am not sure.

I have seen examples of setting the Got/Lost focus events to remove the ButtonElement border once focused, however this removes the highlight border as well as the dashed border which I do not want.

Although I don't like the way it looks it has been tolerable, but now that I have created buttons with a custom shape I need to figure this out.

The dashed border still appears to be square, even though the button itself is not.  I have attached an image that shows what I mean.

Can you please help me remove the dashed borders altogether?  If not, I would at least like them to have the same shape as the button itself.

Thanks for your help.

Mike
Top achievements
Rank 1
 answered on 29 May 2018
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)
Form
Chart (obsolete as of Q1 2013)
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
PdfViewer and PdfViewerNavigator
CommandBar
ListControl
Carousel
GanttView
Diagram, DiagramRibbonBar, DiagramToolBox
Panorama
New Product Suggestions
VirtualGrid
Toolstrip (obsolete as of Q3 2010)
Label
AutoCompleteBox
Spreadsheet
ContextMenu
Panel
Visual Studio Extensions
TitleBar
SplitContainer
Documentation
Map
DesktopAlert
CheckedDropDownList
ProgressBar
MessageBox
TrackBar
Rotator
SpinEditor
CheckedListBox
StatusStrip
Wizard
CollapsiblePanel
LayoutControl
ShapedForm
SyntaxEditor
TextBoxControl
Conversational UI, Chat
DateTimePicker
TabbedForm
CAB Enabling Kit
WaitingBar
GroupBox
DataEntry
ScrollablePanel
ScrollBar
ImageEditor
Tools - VSB, Control Spy, Shape Editor
BrowseEditor
DataFilter
FileDialogs
ColorDialog
Gauges (RadialGauge, LinearGauge, BulletGraph)
ApplicationMenu
RangeSelector
CardView
WebCam
NavigationView
BindingNavigator
RibbonForm
Styling
Barcode
PopupEditor
TaskBoard
Callout
ColorBox
PictureBox
FilterView
Accessibility
VirtualKeyboard
DataLayout
Licensing
ToastNotificationManager
ValidationProvider
CalculatorDropDown
Localization
TimePicker
BreadCrumb
ButtonTextBox
FontDropDownList
BarcodeView
Overlay
Security
LocalizationProvider
Dictionary
TreeMap
StepProgressBar
SplashScreen
Flyout
Separator
SparkLine
ToolbarForm
NotifyIcon
DateOnlyPicker
AI Coding Assistant
Rating
TimeSpanPicker
Calculator
OfficeNavigationBar
TaskbarButton
HeatMap
SlideView
PipsPager
AIPrompt
TaskDialog
TimeOnlyPicker
SpeechToTextButton
SmartPasteButton
+? more
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Shiori
Top achievements
Rank 2
Iron
Tien
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Rob
Top achievements
Rank 4
Bronze
Bronze
Iron
Geoff
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?