I have two problems occcurring in RadGriedView that has GriedViewComboboxCollumn as columns. Here there are:
1 . Creating Data: I set AutoGenerateColumns Property as false and I add two columns by a method (AddColumns) at runtime, each one column is a GridViewComboBoxColumn, defining their ValueMember = ID and DisplayMember = Name, then set datasource of first column, the second column datasource is set based on the select value of the first column. The second column datasource shows the items correctly, but when I select one item of combobox the grid display the ValueMember not the DisplayMember. Why ?
2. After creating Data (even not displaying the correct value), I save the datasource of grid in a IList and clean the gridview. Then I load this IList again in gridview, when I try to edit the value of the second column, the VS shows the message in the picture errortelerik.jpg. Thus, I cannot edit the row or add new row in the gridview.
How Can I handle this error? I already add the radGridView1_DataError event, but not solve the problem, I still not be able to edit the grid.
The code is here. What am I doing wrong?
Thanks.
1 . Creating Data: I set AutoGenerateColumns Property as false and I add two columns by a method (AddColumns) at runtime, each one column is a GridViewComboBoxColumn, defining their ValueMember = ID and DisplayMember = Name, then set datasource of first column, the second column datasource is set based on the select value of the first column. The second column datasource shows the items correctly, but when I select one item of combobox the grid display the ValueMember not the DisplayMember. Why ?
2. After creating Data (even not displaying the correct value), I save the datasource of grid in a IList and clean the gridview. Then I load this IList again in gridview, when I try to edit the value of the second column, the VS shows the message in the picture errortelerik.jpg. Thus, I cannot edit the row or add new row in the gridview.
How Can I handle this error? I already add the radGridView1_DataError event, but not solve the problem, I still not be able to edit the grid.
The code is here. What am I doing wrong?
namespace Example{ public partial class Form1 : Form { IList machineList = new ArrayList(); IList SlotList1 = new ArrayList(); IList SlotList2 = new ArrayList(); IList datasource1 = null; public Form1() { InitializeComponent(); this.radGridView1.MasterGridViewTemplate.AllowCellContextMenu = false; this.radGridView1.MasterGridViewTemplate.AllowColumnChooser = false; this.radGridView1.MasterGridViewTemplate.AllowColumnReorder = false; this.radGridView1.MasterGridViewTemplate.AllowDragToGroup = false; this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false; this.radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; this.radGridView1.MasterGridViewTemplate.EnableGrouping = false; this.radGridView1.MasterGridViewTemplate.EnableSorting = false; this.radGridView1.MasterGridViewTemplate.ShowFilteringRow = false; this.radGridView1.ShowGroupPanel = false; this.radGridView1.ShowNoDataText = false; VO.Machine m1 = new VO.Machine(); m1.IdMachine = 1; m1.MachineName = "Machine1"; VO.Machine m2 = new VO.Machine(); m2.IdMachine = 2; m2.MachineName = "Machine2"; machineList.Add(m1); machineList.Add(m2); VO.Slot s1 = new VO.Slot(); s1.IdMachineSlot = 1; s1.SlotName = "Slot1"; VO.Slot s2 = new VO.Slot(); s2.IdMachineSlot = 3; s2.SlotName = "Slot3"; SlotList1.Add(s1); SlotList1.Add(s2); VO.Slot s3 = new VO.Slot(); s3.IdMachineSlot = 2; s3.SlotName = "Slot2"; VO.Slot s4 = new VO.Slot(); s4.IdMachineSlot = 4; s4.SlotName = "Slot4"; SlotList2.Add(s3); SlotList2.Add(s4); } private void clearForm() { radGridView1.DataSource = null; radGridView1.Columns.Clear(); } protected void AddColumns() { GridViewComboBoxColumn maquinaColumn = new GridViewComboBoxColumn("colMaquina"); maquinaColumn.HeaderText = "Machine"; maquinaColumn.ValueMember = "IdMachine"; maquinaColumn.DisplayMember = "MachineName"; maquinaColumn.FieldName = "IdMachine"; GridViewComboBoxColumn posicaoColumn = new GridViewComboBoxColumn("colPosicao"); posicaoColumn.HeaderText = "Slot"; posicaoColumn.FieldName = "SlotName"; posicaoColumn.ValueMember = "IdMachineSlot"; posicaoColumn.DisplayMember = "SlotName"; radGridView1.Columns.Add(maquinaColumn); radGridView1.Columns.Add(posicaoColumn); } protected void FillColumns() { AddColumns(); ((GridViewComboBoxColumn)this.radGridView1.Columns[0]).DataSource = machineList; } protected void saveDataSource() { datasource1= new ArrayList(); for (int i = 0; i < radGridView1.RowCount; i++) { VO.MachineSlot ms = new VO.MachineSlot(); ms.IdMachine = int.Parse(radGridView1.Rows[i].Cells[0].Value.ToString()); ms.MachineName = "Machine" + ms.IdMachine.ToString(); ms.IdMachineSlot = int.Parse(radGridView1.Rows[i].Cells[1].Value.ToString()); ms.SlotName = "Slot" + ms.IdMachineSlot.ToString(); datasource1.Add(ms); } MessageBox.Show("DataSource1 Saved"); } private void doAction(int action) { switch (action) { case 0: // Build a new datasource clearForm(); datasource1 = null; FillColumns(); break; case 1: saveDataSource(); // Save datasource of radgridview clearForm(); break; case 2: clearForm(); radGridView1.DataSource = datasource1; FillColumns(); break; } } private void radButton1_Click(object sender, EventArgs e) { doAction(0); } private void radButton3_Click(object sender, EventArgs e) { doAction(1); } private void radButton2_Click(object sender, EventArgs e) { doAction(2); } private void onCellEditorInitialized(object sender, GridViewCellEventArgs e) { if (e.Column.HeaderText == "Slot") { if (this.radGridView1.CurrentRow.Cells["IdMachine"].Value != DBNull.Value && this.radGridView1.CurrentRow.Cells["IdMachine"].Value != null) { RadComboBoxEditor editor = (RadComboBoxEditor)this.radGridView1.ActiveEditor; RadComboBoxEditorElement editorElement = (RadComboBoxEditorElement)editor.EditorElement; if (this.radGridView1.CurrentRow.Cells["IdMachine"].Value.ToString().Equals("1")) { editorElement.DataSource = SlotList1; } else editorElement.DataSource = SlotList2; editorElement.SelectedValue = null; editorElement.SelectedValue =this.radGridView1.CurrentCell.Value; } } } }}namespace VO{ public class Machine { private int _id_maquina; private string _cd_maquina; public Machine() { } public int IdMachine { get { return _id_maquina; } set { _id_maquina = value; } } public string MachineName { get { return _cd_maquina; } set { _cd_maquina = value; } } } public class Slot { private int _idMachineSlot; private string _cdSlot; public Slot() { } public int IdMachineSlot { get { return _idMachineSlot; } set { _idMachineSlot = value; } } public string SlotName { get { return _cdSlot; } set { _cdSlot = value; } } } public class MachineSlot { private int _id_maquina; private string _cd_maquina; private int _idMachineSlot; private string _cdSlot; public MachineSlot() { } public int IdMachine { get { return _id_maquina; } set { _id_maquina = value; } } public string MachineName { get { return _cd_maquina; } set { _cd_maquina = value; } } public int IdMachineSlot { get { return _idMachineSlot; } set { _idMachineSlot = value; } } public string SlotName { get { return _cdSlot; } set { _cdSlot = value; } } }}Thanks.