Telerik Forums
UI for WinForms Forum
1 answer
76 views

I have a data entry RadGridView bound to a collection of POCOs. It has some rather compiles editing requirements. On one particular row, there is a cell that requires the edit control to be a multi-selection combo box. On all other rows it requires a numeric entry. I created the column as a GridViewComboBoxColumn. and then tried to create a custom control to replace the standard editor using the EditorRequired event like this:

        private void gvMatrix_EditorRequired(object sender, EditorRequiredEventArgs e)

        {
            if (gvMatrix.CurrentRow.Cells["Comparison"].Value.ToString() == "One of")
            {
                if (e.EditorType == typeof(CustomCheckedListBox))
                    e.EditorType = typeof(CustomCheckedListBox);
            }

//Otherwise I need numeric entry

        }

 

Then, I tried to create the custom control based on the example on the Telerik site (https://docs.telerik.com/devtools/winforms/controls/gridview/editors/using-custom-editors) and came up with this:

 public class CustomCheckedListBox : BaseGridEditor
 {
     protected override RadElement CreateEditorElement()
     {
         return new CustomCheckedListBoxElement();
     }

     public override object Value
     {
         get
         {
             CustomCheckedListBoxElement element = this.EditorElement as CustomCheckedListBoxElement;
             return element.CheckedDropDownElement.Value;
         }
         set
         {
             CustomCheckedListBoxElement element = this.EditorElement as CustomCheckedListBoxElement;
             element.CheckedDropDownElement.Value = value;
         }
     }

     public override void BeginEdit()
     {
         base.BeginEdit();

         CustomCheckedListBoxElement element = this.EditorElement as CustomCheckedListBoxElement;

         var statesData = new List<Dictionary>();

         statesData.Add(new Dictionary { DictionaryKeyString = "AK", Description = "Alaska" });
         statesData.Add(new Dictionary { DictionaryKeyString = "NJ", Description = "New Jersey" });
         statesData.Add(new Dictionary { DictionaryKeyString = "AL", Description = "Alabama" });
         statesData.Add(new Dictionary { DictionaryKeyString = "GA", Description = "Georgia" });

         element.DataSource = statesData;
         element.DropDownStyle = RadDropDownStyle.DropDownList;
         element.ValueMember = "DictionaryKeyString";
         element.DisplayMember = "Description";
     }

     public override bool EndEdit()
     {
         return base.EndEdit();
     }

     //public string? ValueMember { get; set; }
     //public string? DisplayMember { get; set; }
     //public object? DataSource { get; set; }
 }

 public class CustomCheckedListBoxElement : RadCheckedDropDownListElement
 {
     RadCheckedDropDownListElement dropDownListElement = new RadCheckedDropDownListElement();

     public CustomCheckedListBoxElement()
     {
     }

     public RadCheckedDropDownListElement CheckedDropDownElement
     {
         get =>  this.dropDownListElement;           
     }

     protected override void CreateChildElements()
     {
         base.CreateChildElements();
     }
 }

What I get is a an empty dropdown in the cell with no data appearing. Ideally I'd like to instantiate the custom control and pass in the DataSource, ValueMember, etc. so I can reuse it elsewhere. The goal is to retrieve a list of selected states and display them like this when the cell is not in edit mode:

Alabama

New Jersey

Georgia

Any ideas on how to accomplish this?

Thanks

Carl

Dinko | Tech Support Engineer
Telerik team
 answered on 10 Jul 2024
1 answer
173 views

Hello,

is it possible to end edit when user navigates to other cell? The same behavior as standard DataGridView:

I tried to call EndEdit in CurrentCellChanged event handler, but it doesn't work, probably there is something with current cell changing, nor IsInEditMode is not set in this event.

Nadya | Tech Support Engineer
Telerik team
 answered on 10 Jul 2024
1 answer
69 views

Hello,

I would like to help with GridViewComboBoxColumn behavior. I have almost solved how to automatically show popup on click. Next, I want to end edit after selecting some item from combo box, similar to standard DataGridView behavior. I have done this so far:

private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
{
	// automatic combo expanding
	if (radGridView1.IsInEditMode)
		return;

	var cell = sender as GridComboBoxCellElement;
	if (cell == null)
		return;

	radGridView1.BeginEdit();
	var editor = cell.Editor as RadDropDownListEditor;
	if (editor == null)
		return;

	var el = editor.EditorElement as RadDropDownListEditorElement;
	if (el == null)
		return;

	el.SelectedIndexChanged += El_SelectedIndexChanged;

	el.ShowPopup();
}

private void El_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
	var el = sender as RadDropDownListEditorElement;
	if(el == null) 
		return;

	radGridView1.EndEdit();
	el.SelectedIndexChanged -= El_SelectedIndexChanged;
}

I attach SelectedIndexChanged event handler to RadDropDownListEditorElement before showing popup. In this handler, I call EndEdit first and then detach the handler. This works ok except for one case, when user selects the same item, in this case SelectedIndexChanged is not fired, because SelectedIndex hasn't changed:

I tried the same with other events like PopupClosed, but when I cal EndEdit in these events, selected value is not commited. Is it possible to do this somehow? I have attached test project, TelerikTestReal in solution. Thanks.

Nadya | Tech Support Engineer
Telerik team
 answered on 09 Jul 2024
1 answer
93 views

Hello,

I would like to ask about DataError event once more (we discussed it a little in some previous thread). I have tested behavior and program crashes in case of parsing error. First, if I do some validation in underlying data object and throw exception in object property setter, GridView handles it corectly and fires DataError event. But in case of parsing error, for example when I have textbox column, integer property and enter some non-numeric text, program crashes with unhandled exception:

I know, I should use GridViewDecimalColumn, but generally, why GridView doesn't handle parsing error and doesn't fire DataError event also in this case? I have attached also the test project, TelerikTestDataError in solution.

Unhandled exception:
System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.ComponentModel.BaseNumberConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
   at Telerik.WinControls.UI.RadDataConverter.ParseCore(Object value, Type targetType, Type sourceType, TypeConverter dataTypeConverter, IDataConversionInfoProvider dataColumn, Boolean checkFormattedNullValue, CultureInfo cultureInfo)
   at Telerik.WinControls.UI.RadDataConverter.Parse(IDataConversionInfoProvider converstionInfoProvider, Object value, CultureInfo cultureInfo)
   at Telerik.WinControls.UI.GridDataCellElement.set_Value(Object value)
   at Telerik.WinControls.UI.GridViewEditManager.EndEditCore(Boolean validate, Boolean cancel)
   at Telerik.WinControls.UI.GridViewEditManager.EndEdit()
   at Telerik.WinControls.UI.GridRowBehavior.ProcessEnterKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.GridRowBehavior.ProcessKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridBehavior.ProcessKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridBehavior.ProcessKeyDown(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridEditor.OnKeyDown(KeyEventArgs keyEventArgs)
   at Telerik.WinControls.UI.RadTextBoxEditor.OnKeyDown(KeyEventArgs e)
   at Telerik.WinControls.UI.RadTextBoxEditor.TextBoxItem_KeyDown(Object sender, KeyEventArgs e)
   at System.Windows.Forms.KeyEventHandler.Invoke(Object sender, KeyEventArgs e)
   at Telerik.WinControls.RadItem.OnKeyDown(KeyEventArgs e)
   at Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyDown(Object sender, KeyEventArgs e)
   at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
   at System.Windows.Forms.TextBox.WndProc(Message& m)
   at Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Nadya | Tech Support Engineer
Telerik team
 answered on 09 Jul 2024
1 answer
38 views
Hi,
    I can add context menu when right click on the grid, but based on selected value from context menu, i want to hide / show the rows.
Ex: Grid have 4 column's,  One of the column name is "Status", in that we get "Export" , "Done" and "Pending" for each rows, so i show there 3 values in context menu when right click on the grid using following code


'Declaration Private contextMenu1 As RadContextMenu 'Page Load contextMenu1 = New RadContextMenu() Dim menuItem1 As New RadMenuItem("Export") menuItem1.ForeColor = Color.Red AddHandler menuItem1.Click, AddressOf rmi1_Click Dim menuItem2 As New RadMenuItem("Verification") AddHandler menuItem2.Click, AddressOf rmi2_Click contextMenu1.Items.Add(menuItem1) contextMenu1.Items.Add(menuItem2) 'Code for show context menu Private Sub RadGridView1_ContextMenuOpening(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles RadGridView1.ContextMenuOpening e.ContextMenu = contextMenu1.DropDown End Sub 'Menu click event Private Sub rmi2_Click(sender As Object, e As EventArgs) sender.Visible = CDec(sender.Row.Cells("Status").Value) = "Export" End Sub Private Sub rmi1_Click(sender As Object, e As EventArgs) sender.Visible = CDec(sender.Row.Cells("Status").Value) = "Done" End Sub

 Private Sub rmi1_Click(sender As Object, e As EventArgs)
        sender.Visible = CDec(sender.Row.Cells("Status").Value) = "Pending"
 End Sub

Thanks and Regards
Aravind
Dinko | Tech Support Engineer
Telerik team
 answered on 08 Jul 2024
2 answers
59 views

I have created a custom PropertyGridItemElement for my RadPropertyGrid to hold a button.  When the user clicks the button, the click handler performs some action, but the action is based on data that is known by the form that contains the propertygrid that contains the custom element.  How do I arrange for that data to be available to the button's Click handler?  The constructor of the custom element isn't even called explicitly -- it's implicit in 

PropertyGrid.CreateItemElement += (sender, args) =>
{
if (args.Item.Name == nameof(LabelWrapper.Button))
{
args.ItemElementType = typeof(CustomPropertyGridItemElement);
}
};

Thanks in advance.

Michael
Top achievements
Rank 1
Iron
Iron
Veteran
 answered on 04 Jul 2024
14 answers
518 views
I have a RadPageView (DetailTabControl).  I want to change the strip item's back color to red under some condition.  Then I might need to change it back.  I figured out how to change it to red.  Restoring the prior values does not restore the tab as I expected.  The back color (which I caught before setting to Red, ARGB(255, 191, 219, 255)) is for that of the PageView, not the PageViewPage.  Please see attached images.

public class Globals
{
public static Color DefaultTabColor = Color.FromArgb(255, 191, 219, 255);
}
...
private void CancelTab(int offset)
{
     DetailTabControl.Pages[offset].Item.DrawFill = true;
     DetailTabControl.Pages[offset].Item.NumberOfColors = 1;
     DetailTabControl.Pages[offset].Item.BackColor = Color.Red;   
}
private void UncancelTab(int offset)
{
     DetailTabControl.Pages[offset].Item.BackColor = Globals.DefaultTabColor;
     DetailTabControl.Pages[offset].Item.NumberOfColors = 2;
     DetailTabControl.Pages[offset].Item.DrawFill = false;
}

Álvaro
Top achievements
Rank 1
Iron
Iron
 answered on 02 Jul 2024
1 answer
94 views
Hi,
     I want to enable up and down key for  rad grid to select to row and get values from that. In winform how to achieve this ?

Note:  My grid have simply row it not have sub grid or some other. Please provide sample code in vb .

Pls replace asap.

Regards
Aravind
Nadya | Tech Support Engineer
Telerik team
 answered on 27 Jun 2024
1 answer
54 views
1
Nadya | Tech Support Engineer
Telerik team
 answered on 27 Jun 2024
1 answer
99 views

Using RadCalendar and I thought is would be simple

I want all dates in the past to be disabled and I thought this would do it:

        private void radCalendar1_ElementRender(object sender, RenderElementEventArgs e)

        {
            if (e.Day.Date < DateTime.Now)
                e.Day.Disabled = true;
        }

Th goals is to have it look like this but it seems to have no effect and I can selected dates that the code set as disabled.

What am I missing?

Thanks

Carl

Nadya | Tech Support Engineer
Telerik team
 answered on 18 Jun 2024
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
DateTimePicker
CollapsiblePanel
Conversational UI, Chat
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
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?