This is a migrated thread and some comments may be shown as answers.

Binding 2 combox inside radgridview

14 Answers 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Praveena
Top achievements
Rank 1
Praveena asked on 22 Feb 2011, 09:42 AM
Hi All,

         Actually i am new to telerik controls. Am using c#. My senario is - I have a radgridview. Inside that first column and second column are comboxcolumns. Users are allowed to add rows to gridview. And then click save button to save all the rows into database. Once i select the project from my first combo column all the tasks based on that project should get binded in second combocolumn of that radgrid. I am able to bind the second column based on the first column selected value. However, My problem is- Once i go to 2nd row in the gridview. the first row's secondcolumn which i already selected goes blank. And 2nd rows value is visble. When i move to 3rd row, the first 2 rows selected value in 2nd column goes blank. I mean at a time only one row value is visible for 2nd column. Anyone kindly provide me with the solution.

14 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 22 Feb 2011, 11:04 AM
Hello,

I have added a sample for you below that is working correctly. This was updated from the following forum post

Designer File
namespace WindowsApplication6
{
    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.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).BeginInit();
            this.SuspendLayout();
            // 
            // radGridView1
            // 
            this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.radGridView1.Location = new System.Drawing.Point(0, 0);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(374, 305);
            this.radGridView1.TabIndex = 0;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(374, 305);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadGridView radGridView1;
    }
}

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace WindowsApplication6
{
    public partial class Form1 : Form
    {
        BindingList<Food> fullList;
        BindingList<Food> fruitsList;
        BindingList<Food> vegetablesList;
  
        public Form1()
        {
            InitializeComponent();
  
            this.radGridView1.CellEditorInitialized += new Telerik.WinControls.UI.GridViewCellEventHandler(radGridView1_CellEditorInitialized);
  
            fullList = new BindingList<Food>();
            fullList.Add(new Food(0, "Onion"));
            fullList.Add(new Food(1, "Cucumber"));
            fullList.Add(new Food(2, "Tomato"));
            fullList.Add(new Food(3, "Peach"));
            fullList.Add(new Food(4, "Banana"));
            fullList.Add(new Food(5, "Grape"));
  
            fruitsList = new BindingList<Food>();
            fruitsList.Add(fullList[3]);
            fruitsList.Add(fullList[4]);
            fruitsList.Add(fullList[5]);
  
            vegetablesList = new BindingList<Food>();
            vegetablesList.Add(fullList[0]);
            vegetablesList.Add(fullList[1]);
            vegetablesList.Add(fullList[2]);
  
            BindingList<FoodType> typesList = new BindingList<FoodType>();
            typesList.Add(new FoodType(0, "Vegetables"));
            typesList.Add(new FoodType(1, "Fruit"));
  
            GridViewComboBoxColumn foodType = new GridViewComboBoxColumn();
            foodType.FieldName = "FoodType";
            this.radGridView1.Columns.Add(foodType);
            foodType.DataSource = typesList;
            foodType.Width = 100;
            foodType.DisplayMember = "FoodTypeName";
            foodType.ValueMember = "FoodTypeID";
  
            GridViewComboBoxColumn food = new GridViewComboBoxColumn();
            food.FieldName = "Food";
            this.radGridView1.Columns.Add(food);
            food.DataSource = fullList;
            food.Width = 100;
            food.DisplayMember = "FoodName";
            food.ValueMember = "FoodID";
  
            this.radGridView1.Rows.Add(new object[] { 0, 1 });
            this.radGridView1.Rows.Add(new object[] { 1, 4 });
            this.radGridView1.Rows.Add(new object[] { 1, 3 });
            this.radGridView1.Rows.Add(new object[] { 0, 0 });
            this.radGridView1.Rows.Add(new object[] { 0, 2 });
            this.radGridView1.Rows.Add(new object[] { 0, 1 });
            this.radGridView1.Rows.Add(new object[] { 1, 4 });
            this.radGridView1.Rows.Add(new object[] { 1, 3 });
            this.radGridView1.Rows.Add(new object[] { 0, 0 });
            this.radGridView1.Rows.Add(new object[] { 0, 2 });
            this.radGridView1.Rows.Add(new object[] { 0, 1 });
            this.radGridView1.Rows.Add(new object[] { 1, 4 });
            this.radGridView1.Rows.Add(new object[] { 1, 3 });
            this.radGridView1.Rows.Add(new object[] { 0, 0 });
            this.radGridView1.Rows.Add(new object[] { 0, 2 });
        }
  
        void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (e.Column.HeaderText == "Food")
            {
                if (this.radGridView1.CurrentRow.Cells["FoodType"].Value != DBNull.Value
                    && this.radGridView1.CurrentRow.Cells["FoodType"].Value != null)
                {
                    RadDropDownListEditor editor = (RadDropDownListEditor)this.radGridView1.ActiveEditor;
                    RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
                    if (int.Parse(this.radGridView1.CurrentRow.Cells["FoodType"].Value.ToString()) == 0)
                    {
                        editorElement.DataSource = vegetablesList;
                    }
                    else
                    {
                        editorElement.DataSource = fruitsList;
                    }
                    editorElement.SelectedValue = null;
                    editorElement.SelectedValue = this.radGridView1.CurrentCell.Value;
                }
            }
        }
    }
  
    public class FoodType
    {
        private int foodTypeID;
  
        public int FoodTypeID
        {
            get { return foodTypeID; }
            set { foodTypeID = value; }
        }
  
        private string foodType;
  
        public string FoodTypeName
        {
            get { return foodType; }
            set { foodType = value; }
        }
  
        public FoodType(int foodTypeID, string foodType)
        {
            this.foodTypeID = foodTypeID;
            this.foodType = foodType;
        }
    }
  
    public class Food
    {
        private int foodID;
  
        public int FoodID
        {
            get { return foodID; }
            set { foodID = value; }
        }
  
        private string foodName;
  
        public string FoodName
        {
            get { return foodName; }
            set { foodName = value; }
        }
  
        public Food(int foodID, string foodName)
        {
            this.foodID = foodID;
            this.foodName = foodName;
        }
    }
}

hope you find that helpful
Regards,
Richard
0
Praveena
Top achievements
Rank 1
answered on 22 Feb 2011, 11:51 AM

Hi Richard,

           Thnx for ur reply. Still I have some problem. Let me be more clear..

Previously, In cell begin event I have written the following code..

private void grvProjectTSEntry_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)

        {

{

if (this.grvProjectTSEntry.CurrentColumn.Index == 2)// checking for my 2nd column. Below code works only if begin edit of 2nd combo column

                {

                    if (grvProjectTSEntry.CurrentRow.Cells["colProject"].Value != null)//if my first combocolumn value is not null

                    {

                        #region Binding task on the basis of project selection

                        if (!string.IsNullOrEmpty(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()))

                        {

                            GridViewComboBoxColumn column = this.grvProjectTSEntry.CurrentColumn as GridViewComboBoxColumn; // creating column for the 2nd combocolumn's current column

                            if (grvProjectTSEntry.CurrentRow.Cells["colProject"].Value != null)

                            {

                                if (Convert.ToInt32(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()) != 0)

                                {

                                    objTimesheetEntry = objTimesheetEntryMgr.BindTask(Time.Share.Site.CompanyID, Convert.ToInt32(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()) //Calling the query to fill dataset with project id as filteration);

                                    column.DataSource = objTimesheetEntry.Time_Ds.Tables[0]; ";//Now 2nd combo column gets binded with that result dataset

                                    column.ValueMember = "TaskId";                                

                                    column.DisplayMember = "Task";

                                    grvProjectTSEntry.CurrentRow.Cells["colTask"].Value = 0; // Initially <<Please select>> will get selected to that 2nd combo column

                                }

                            }

                        }

                    }

                        #endregion

                }

}

This code perfectly helps me to bind the 2nd combo with proper values. However as I told earlier the column refreshes with no value when I go to the same column in any other row.

Now,I tried the code you gave in and commented out my code in begin edit:

See below

   private void grvProjectTSEntry_CellEditorInitialized(object sender, GridViewCellEventArgs e)

        {

            if (this.grvProjectTSEntry.CurrentColumn.Index == 2)

            {

                if (grvProjectTSEntry.CurrentRow.Cells["colProject"].Value != null)

                {

                    #region Binding task on the basis of project selection

                    if (!string.IsNullOrEmpty(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()))

                    {

                        RadDropDownListEditor editor = (RadDropDownListEditor)this.grvProjectTSEntry.ActiveEditor;

                        RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;

                        GridViewComboBoxColumn column = this.grvProjectTSEntry.CurrentColumn as GridViewComboBoxColumn;

                        if (int.Parse(this.grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()) > 0)

                        {

                            objTimesheetEntry = objTimesheetEntryMgr.BindTask(Time.Share.Site.CompanyID, Convert.ToInt32(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()));//this is to call the query which will fill the dataset

                            column.DataSource = objTimesheetEntry.Time_Ds.Tables[0];

                            column.ValueMember = "TaskId";

                            column.DisplayMember = "Task";

                        }

                        editorElement.SelectedValue = 0; //0 cos for me it should bind with default value i.e <<Please select>>

                        editorElement.SelectedValue = this.grvProjectTSEntry.CurrentCell.Value;

                    }

                }

                    #endregion

            }

        }

Here binding itself is getting a problem. First row binds properly. Once I select project in second row, the first row comb binding is also getting disturbed. As am new I may be doing something wrong. It would be really very gr8 if you could help me in correcting it

0
Richard Slade
Top achievements
Rank 2
answered on 22 Feb 2011, 12:10 PM
Hello,

If I understand correctly, you'd like (taking the Fruit/Veg exmaple) that when you change from Fruit to Vegatable, then the other column selects a default value. is that correct?
Thanks
Richard
0
Praveena
Top achievements
Rank 1
answered on 22 Feb 2011, 12:26 PM
Hi,

         My requiremnet is when i select fruit in forst combo , the second combo binds with :
<<please select>>//default value(selected value by default)
apple
orange

If i select vegetable in first column, hen my second combo column binds with:
<<please select>>//default value(selected value by default)
Onion
Cucumber

So i should be able to select as many rows as i want and on clicking save button it saves into database. To be more clear, say for eg, i ve 4 columns in grid:
first column foodtype, second column food, third cloumn quantity, fourth column price

1st row - by default comes with <<please select>>. Now i select fruits. then 2nd column binds with values i select apple, qty 3, price - xxx
2nd row- by default comes with <<please select>>. Now i select fruits. then 2nd column binds with values i select orange, qty 6, price - xxx
3rd  row- by default comes with <<please select>>. Now i select veg. then 2nd column binds with values i select onion, qty 10, price - xxx
... (as many rows as i wan).
Now save button will save into database.

Out of this scenario, I am able to
1) populate first column with foodtype with <<please select>> as selected value.
2) when some one selects fruits, my second combo will bind
        <<please select>>//default value(selected value by default)
        apple
        orange
3) add all other columns and save..
Note :
Perfectly works if there is just one row.

My Problem
1) 1st row - user selected foodtype fruits, food apple, qty 3, price XXX
2) 2nd row- user selects food type vegetables, now problem starts : this second row gets binded with
      <<please select>>//default value(selected value by default)
     Onion
     Cucumber
However in the 1st row my food column goes blank. 2 nd row has proper value now.
If i add 3rd row with again fruit as food type, then 3 rd works properly however 1st and 2 row's food column goes blank.

How to handle this going blank problem. Any idea why it occurs?
0
Praveena
Top achievements
Rank 1
answered on 22 Feb 2011, 12:51 PM
Hi ,

    With your code sample, i am able to prevent combo column refresh now. Now everything works fine except for a problem. once i select onion as food and press tab, food onion is getting changed to 1(means the value member instead of display member.). Combo is binding with displany member. Once i select a food it binds the display member, however when i press tab, it binds value member. Any idea what could be the problem?
Thnx in advnace

Regards,
Praveena
0
Richard Slade
Top achievements
Rank 2
answered on 22 Feb 2011, 12:57 PM
Hello,

Do you have the display member and value member set up correctly?
E.g
food.DisplayMember = "FoodName";
food.ValueMember = "FoodID";

If you do, then please can you post a code sample using the Format Code Block and I'll take a look for you
Richard
0
Praveena
Top achievements
Rank 1
answered on 22 Feb 2011, 01:03 PM
if (this.grvProjectTSEntry.CurrentColumn.Index == 2)
            {
                if (grvProjectTSEntry.CurrentRow.Cells["colProject"].Value != null)
                {
                   
                    if (!string.IsNullOrEmpty(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()))
                    {
                        RadDropDownListEditor editor = (RadDropDownListEditor)this.grvProjectTSEntry.ActiveEditor;
                        RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
                                 if (int.Parse(this.grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()) > 0)
                        {
                            objTimesheetEntry = objTimesheetEntryMgr.BindTask(Time.Share.Site.CompanyID, Convert.ToInt32(grvProjectTSEntry.CurrentRow.Cells["colProject"].Value.ToString()));
                            editorElement.DataSource = objTimesheetEntry.Time_Ds.Tables[0];
                            editorElement.ValueMember = "TaskId";
                            editorElement.DisplayMember = "Task";
                        }
                       editorElement.SelectedValue = 0;
                        editorElement.Text = this.grvProjectTSEntry.CurrentCell.Text;
                    }
                    
                }
            }

My dataset ( datasource for editor element) has 2 columns one task id(0,1,2) and second task(testing, developing, maintenance).

Regards,
Praveena
0
Richard Slade
Top achievements
Rank 2
answered on 22 Feb 2011, 01:32 PM
Hello,

I can't replicate your issue, but my guess is that you haven't set up (in your real application) the Display and Value member for the column (not in the CellEditorInitialized event).

E.g.
GridViewComboBoxColumn food = new GridViewComboBoxColumn();
food.FieldName = "Food";
this.radGridView1.Columns.Add(food);
food.DataSource = fullList;
food.Width = 100;
food.DisplayMember = "FoodName";
food.ValueMember = "FoodID";

Richard
0
Praveena
Top achievements
Rank 1
answered on 22 Feb 2011, 01:44 PM
Hello,

          I am not creating the combocolumns(or any other columns in this grid) programatically but by design. In the column properties i ve set display member and value member. In my another form, the same second combocolumn is getting binded but not based on first combocolumn. It is based on selected value in dropdown list outside grid. There i ve coded like below:

if (ddlProjectRef.SelectedIndex.ToString() != null)
                {
                    if (ddlProjectRef.SelectedIndex != -1)
                    {
                        objTimesheetEntry = objTimesheetEntryMgr.BindActivity(Time.Share.Site.CompanyID, Convert.ToInt32(ddlProjectRef.SelectedValue.ToString()));
 
                        ((Telerik.WinControls.UI.GridViewComboBoxColumn)this.grvEmployeeTSEntry.Columns["colActivity"]).DataSource = objTimesheetEntry.Time_Ds.Tables[0];
                        ((Telerik.WinControls.UI.GridViewComboBoxColumn)this.grvEmployeeTSEntry.Columns["colActivity"]).ValueMember = "ID";
                        ((Telerik.WinControls.UI.GridViewComboBoxColumn)this.grvEmployeeTSEntry.Columns["colActivity"]).DisplayMember = "Activity";
 
                        if (grvEmployeeTSEntry.Rows.Count > 0)
                        {
                            grvEmployeeTSEntry.Rows[0].Cells["colActivity"].Value = 0;
                        }
 
 
                    }
                }

and it is working fine. In this form am binding only in celleditorinitalized. Is that wrong? After creating column in design am binding just in cellEditorinitialized. Should i bind anywhere else. ?Kindly let me know if yes, in which event i have to bind. As this second combocolumn is based on first combocolumn i thought binding it before the first combocolumn get its value is meaningless. That why i didnt bind it before

Regards,
Praveena devi
0
Praveena
Top achievements
Rank 1
answered on 22 Feb 2011, 01:57 PM
Hello,

       From my designer file

gridViewComboBoxColumn2.DisplayMember = "Task";
    gridViewComboBoxColumn2.FormatString = "";
    gridViewComboBoxColumn2.HeaderText = "Task";
    gridViewComboBoxColumn2.Name = "colTask";
    gridViewComboBoxColumn2.ValueMember = "TaskId";
    gridViewComboBoxColumn2.Width = 150;

In my designer file, it is set value memebr and display memeber. Is it not enough?. Should i bind once again before binding in celleditorinitialized

REgards,
Praveena
0
Richard Slade
Top achievements
Rank 2
answered on 22 Feb 2011, 02:02 PM
Hello,

I am having trouble replicating your issue with the exmaple that I have so far. Please can you amend the Fruit and Veg exmaple to mirror your issue?
If so, then I'll be able to take a look at it for you, but I think at the moment, we are working from two different sets of code
thanks
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 22 Feb 2011, 02:48 PM
Hello,

I have altered the Form1.cs file to be how I think you would like it. Please can you try this.

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace WindowsApplication6
{
    public partial class Form1 : Form
    {
        BindingList<Food> fullList;
        BindingList<Food> fruitsList;
        BindingList<Food> vegetablesList;
        private RadDropDownListEditorElement m_editorelement;
  
        public Form1()
        {
            InitializeComponent();
  
            this.radGridView1.CellEditorInitialized += new Telerik.WinControls.UI.GridViewCellEventHandler(radGridView1_CellEditorInitialized);
  
            fullList = new BindingList<Food>();
            fullList.Add(new Food(0, "Onion"));
            fullList.Add(new Food(1, "Cucumber"));
            fullList.Add(new Food(2, "Tomato"));
            fullList.Add(new Food(3, "Peach"));
            fullList.Add(new Food(4, "Banana"));
            fullList.Add(new Food(5, "Grape"));
  
            fruitsList = new BindingList<Food>();
            fruitsList.Add(fullList[3]);
            fruitsList.Add(fullList[4]);
            fruitsList.Add(fullList[5]);
  
            vegetablesList = new BindingList<Food>();
            vegetablesList.Add(fullList[0]);
            vegetablesList.Add(fullList[1]);
            vegetablesList.Add(fullList[2]);
  
            BindingList<FoodType> typesList = new BindingList<FoodType>();
            typesList.Add(new FoodType(0, "Vegetables"));
            typesList.Add(new FoodType(1, "Fruit"));
  
            GridViewComboBoxColumn foodType = new GridViewComboBoxColumn();
            foodType.FieldName = "FoodType";
            this.radGridView1.Columns.Add(foodType);
            foodType.DataSource = typesList;
            foodType.Width = 100;
            foodType.DisplayMember = "FoodTypeName";
            foodType.ValueMember = "FoodTypeID";
  
            GridViewComboBoxColumn food = new GridViewComboBoxColumn();
            food.FieldName = "Food";
            this.radGridView1.Columns.Add(food);
            food.DataSource = fullList;
            food.Width = 100;
            food.DisplayMember = "FoodName";
            food.ValueMember = "FoodID";
  
            this.radGridView1.Rows.Add(new object[] { 0, 1 });
            this.radGridView1.Rows.Add(new object[] { 1, 4 });
            this.radGridView1.Rows.Add(new object[] { 1, 3 });
            this.radGridView1.Rows.Add(new object[] { 0, 0 });
            this.radGridView1.Rows.Add(new object[] { 0, 2 });
            this.radGridView1.Rows.Add(new object[] { 0, 1 });
            this.radGridView1.Rows.Add(new object[] { 1, 4 });
            this.radGridView1.Rows.Add(new object[] { 1, 3 });
            this.radGridView1.Rows.Add(new object[] { 0, 0 });
            this.radGridView1.Rows.Add(new object[] { 0, 2 });
            this.radGridView1.Rows.Add(new object[] { 0, 1 });
            this.radGridView1.Rows.Add(new object[] { 1, 4 });
            this.radGridView1.Rows.Add(new object[  ] { 1, 3 });
            this.radGridView1.Rows.Add(new object[] { 0, 0 });
            this.radGridView1.Rows.Add(new object[] { 0, 2 });
        }
  
        void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (e.Column.HeaderText == "Food")
            {
                if (this.radGridView1.CurrentRow.Cells["FoodType"].Value != DBNull.Value
                    && this.radGridView1.CurrentRow.Cells["FoodType"].Value != null)
                {
                    RadDropDownListEditor editor = (RadDropDownListEditor)this.radGridView1.ActiveEditor;
                    RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
                    if (int.Parse(this.radGridView1.CurrentRow.Cells["FoodType"].Value.ToString()) == 0)
                    {
                        editorElement.DataSource = vegetablesList;
                    }
                    else
                    {
                        editorElement.DataSource = fruitsList;
                    }
  
                    editorElement.SelectedValue = null;
                    editorElement.SelectedValue = this.radGridView1.CurrentCell.Value;
                }
            }
            else if(e.Column.HeaderText == "FoodType")
            {
                RadDropDownListEditor editor = (RadDropDownListEditor)this.radGridView1.ActiveEditor;
                RadDropDownListEditorElement editorElement = (RadDropDownListEditorElement)editor.EditorElement;
  
                m_editorelement = editorElement;
                editorElement.SelectedValueChanged += new Telerik.WinControls.UI.Data.ValueChangedEventHandler(editorElement_SelectedValueChanged);
            }
        }
  
        void editorElement_SelectedValueChanged(object sender, Telerik.WinControls.UI.Data.ValueChangedEventArgs e)
        {
            if (m_editorelement.Text == "Fruit")
            {
                this.radGridView1.CurrentRow.Cells["Food"].Value = 3;
            }
            else
            {
                this.radGridView1.CurrentRow.Cells["Food"].Value = 0;
            }
        }
  
        private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
        {
            if (e.Column.Name == "FoodType")
            {
                e.Row.Cells["Food"].BeginEdit();
            }
        }
  
  
    }
  
    public class FoodType
    {
        private int foodTypeID;
  
        public int FoodTypeID
        {
            get { return foodTypeID; }
            set { foodTypeID = value; }
        }
  
        private string foodType;
  
        public string FoodTypeName
        {
            get { return foodType; }
            set { foodType = value; }
        }
  
        public FoodType(int foodTypeID, string foodType)
        {
            this.foodTypeID = foodTypeID;
            this.foodType = foodType;
        }
    }
  
    public class Food 
  
    {
        private int foodID;
  
        public int FoodID
        {
            get { return foodID; }
            set { foodID = value; }
        }
  
        private string foodName;
  
        public string FoodName
        {
            get { return foodName; }
            set { foodName = value; }
        }
  
        public Food(int foodID, string foodName)
        {
            this.foodID = foodID;
            this.foodName = foodName;
        }
    }
}

thanks
Richard
0
Praveena
Top achievements
Rank 1
answered on 23 Feb 2011, 06:57 AM
Hey,

   Thnx a lot!! Finally its working perfectly fine.

The mistake i did:

Though we give, display member and value member in design mode of radgrid through properties, we have to bind it in form programatically. So I binded the second column with all values initially in the form, then in celleditorinitialized event, again bind the second column with filteration from first column selected value.

You are so helpful and resolved the problem for which am trying to resolve last 3 days.

Thnx,
Praveena
0
Richard Slade
Top achievements
Rank 2
answered on 23 Feb 2011, 09:56 AM
Glad I could be of help.
All the best
Richard
Tags
GridView
Asked by
Praveena
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Praveena
Top achievements
Rank 1
Share this question
or