I need to have a column in the grid where a user can either select a value from a list or type in a value. For example, if the user is enter a face amount for a life insurance policy the user can either select one of these three options: Minimum, Maximum, Target or enter a number from 100,000 to 10,000,000.
I tried using the GridViewComboBoxColumn and setting the DropDownStyle to DropDown. This allowed me to edit the value in the cell, but when I leave the cell, the cell's display value flips back to what it was previously.
In the example attached, click on the first row where it says 'Minimum' and type in 100000, then hit the tab key to move to a new cell. The cell flips from 100000 back to 'Minimum'.
Is there a way to use the GridViewComboBoxColumn to allow the user to either select a value from the drop down list or type in a value?
Here is the Form1.Designer.cs file:
Here is the sample Form1.cs file:
I tried using the GridViewComboBoxColumn and setting the DropDownStyle to DropDown. This allowed me to edit the value in the cell, but when I leave the cell, the cell's display value flips back to what it was previously.
In the example attached, click on the first row where it says 'Minimum' and type in 100000, then hit the tab key to move to a new cell. The cell flips from 100000 back to 'Minimum'.
Is there a way to use the GridViewComboBoxColumn to allow the user to either select a value from the drop down list or type in a value?
Here is the Form1.Designer.cs file:
namespace GridComboBoxColumn
{
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()
{
this._grid = new Telerik.WinControls.UI.RadGridView();
((System.ComponentModel.ISupportInitialize)(this._grid)).BeginInit();
this.SuspendLayout();
//
// _grid
//
this._grid.Location = new System.Drawing.Point(13, 13);
this._grid.Name = "_grid";
this._grid.Size = new System.Drawing.Size(259, 237);
this._grid.TabIndex = 0;
this._grid.Text = "radGridView1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this._grid);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this._grid)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Telerik.WinControls.UI.RadGridView _grid;
}
}
Here is the sample Form1.cs file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.Primitives;
using Telerik.WinControls.UI;
namespace GridComboBoxColumn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetupGrid();
}
private void SetupGrid()
{
// Add Column
{
GridViewComboBoxColumn column = new GridViewComboBoxColumn();
column.Name = "Policy.FaceAmount";
column.HeaderText = "Total Face Amount";
column.ValueMember = "Value";
column.DisplayMember = "Name";
column.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
column.ReadOnly = false;
BindingList<
QuestionSelectionItem
> list = new BindingList<
QuestionSelectionItem
>();
list.Add(new QuestionSelectionItem("Minimum", "MIN"));
list.Add(new QuestionSelectionItem("Maxmimum", "MAX"));
list.Add(new QuestionSelectionItem("Target", "TGT"));
column.DataSource = list;
_grid.Columns.Add(column);
}
// Add Row
{
// First Row
{
GridViewRowInfo row = _grid.Rows.AddNew();
row.Cells["Policy.FaceAmount"].Value = "MIN";
}
// Second Row
{
GridViewRowInfo row = _grid.Rows.AddNew();
row.Cells["Policy.FaceAmount"].Value = "100000";
}
// Third Row
{
GridViewRowInfo row = _grid.Rows.AddNew();
row.Cells["Policy.FaceAmount"].Value = "MAX";
}
}
}
protected class QuestionSelectionItem
{
private string _name = null;
private string _value = null;
public QuestionSelectionItem(string aName, string aValue)
{
_name = aName;
_value = aValue;
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Value
{
get { return _value; }
set { _value = value; }
}
}
}
}