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

Fill second Column with type GridViewComboBoxColumn on selection change of frist GridViewComboBoxColumn

9 Answers 338 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sally Attalla
Top achievements
Rank 1
Sally Attalla asked on 17 May 2010, 08:33 AM
Hello,]
I try  with telerik  since  1 month  i   use  c#.
I have  two column  with type of GridViewComboBoxColumn    , In current  row  when value of frist  colunm changed  I want  to fill a cell  of second column with a datasource  depend on  a first    column.
i see  almost  of  Forums  related  to this  point  , but     I cant  find  what i want.
 

9 Answers, 1 is accepted

Sort by
0
Rasha Abdelhameed
Top achievements
Rank 1
answered on 17 May 2010, 12:17 PM
Hi
Also i have the same problem any one can help to solve this problem
Thanks.
0
Rasha Abdelhameed
Top achievements
Rank 1
answered on 17 May 2010, 01:32 PM
Hello,
i found this solution in his link :
http://www.telerik.com/community/forums/winforms/gridview/populate-a-combo-based-on-another-combo-within-same-gridview.aspx
but it isn't what i want exactly i need when i change the value in first comboBox i can change datasource to the second one when still the first cell the current cell not when move to the second one.
any one can help me.
Thanks


0
Jack
Telerik team
answered on 19 May 2010, 03:35 PM
Hello Rasha Abdelhameed,

I suppose that you want to change the cell value based on another cell's value. If this is the case, you can do this by handling the ValueChanged event. Here is a sample:

void radGridView1_ValueChanged(object sender, EventArgs e)
{
    RadComboBoxEditor editor = sender as RadComboBoxEditor;
    if (editor != null && ((GridViewDataColumn)this.radGridView1.CurrentColumn).UniqueName == "c1")
    {
        RadComboBoxEditorElement editorElement = editor.EditorElement as RadComboBoxEditorElement;
        this.radGridView1.CurrentRow.Cells["c2"].Value = editorElement.SelectedIndex + 1;
        this.radGridView1.CurrentRow.InvalidateRow();
    }
}

I hope this helps. If you have further questions, please specify the desired behavior in detail. I am looking to your reply.

 

Kind regards,
Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rasha Abdelhameed
Top achievements
Rank 1
answered on 20 May 2010, 12:41 PM
Hi Jack ,
Thankes  for  your help.
I try  what  you say  but this  soluation  is  not  what  i want,
I  want  when  CellEditorInitialized  on  frist column  with type GridViewComboBoxColumn    set a data source of secound coulmn  with type GridViewComboBoxColumn.

Kind regards
Rasha

0
Jack
Telerik team
answered on 21 May 2010, 02:10 PM
Hi Rasha Abdelhameed,

I am not sure that I understand your scenario. You can still use the ValueChanged event to change the data source of the desired column.  However, this will change the data source for the whole column and because of this all value in the column. Alternative option is to handle CellFormatting event and display to customize the displayed value. Here is a sample:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridViewDataColumn column = e.CellElement.ColumnInfo as GridViewDataColumn;
    if (column != null && column.UniqueName == "Value")
    {
        e.CellElement.Text = GetLookupValue((int)e.CellElement.RowInfo.Cells["Combo"].Value);
    }
}


Greetings,

Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rasha Abdelhameed
Top achievements
Rank 1
answered on 22 May 2010, 08:37 AM
Hi Jack ,
Thanks a lot for your replay and I'm very sorry i can't explain my problem
my problem is :
i have two gridViewComboBoxColumn i want when the user change the value of one column (by choose)
the second one change its data source depend on the value i change from the first
like if the first  column its datasource is all countries so, when i choose one of them the second comboBoxColumn change its
dataSource which contain the cities of specific country .Also, i want to change cities column when i still editing countries column .
Thanks a lot,
Rasha



0
Jack
Telerik team
answered on 27 May 2010, 09:53 AM
Hello Rasha Abdelhameed,

I understand. The solution presented in this forum post implements exactly the scenario you are describing. However, you have to handle the CellFormatting event and update cell text manually based on your other column like I said in my previous post. This is so, because the DataSource property is responsible for the whole column and changing it will cause all cell values to change. I hope this helps.

All the best,
Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sally Attalla
Top achievements
Rank 1
answered on 27 May 2010, 11:58 AM
hello  Jack ,
this is  solve  my  problem

 private void dgridSubParts_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            GridViewRowInfo row = e.Row as GridViewRowInfo;
            RadComboBoxEditor editor = dgridSubParts.ActiveEditor as RadComboBoxEditor;
            editoropertaion = dgridSubParts.ActiveEditor as RadComboBoxEditor;
            try
            {
                phaseID = Convert.ToInt32(dgridSubParts.CurrentRow.Cells["colPhase"].Value);
                if (e.ColumnIndex == 0)
                {

                    editor.ValueChanging += new ValueChangingEventHandler(Editor_ValueChanging);
                    ((RadComboBoxEditorElement)(editor).EditorElement).RightToLeft = true;


                }
                else if (e.ColumnIndex == 1 && phaseID != 0)
                {
                    editor.ValueChanging -= new ValueChangingEventHandler(Editor_ValueChanging);

                    ((RadComboBoxEditorElement)(editor).EditorElement).RightToLeft = true;
                    ((RadComboBoxEditorElement)(editor).EditorElement).DropDownStyle = RadDropDownStyle.DropDownList;

                    ((RadComboBoxEditorElement)(editor).EditorElement).DisplayMember = Man_Set_Operation.ColumnNames.OperationName;
                    ((RadComboBoxEditorElement)(editor).EditorElement).ValueMember = Man_Set_Operation.ColumnNames.OperationId;
                    ((RadComboBoxEditorElement)(editor).EditorElement).DataSource = frmAddPart.ReturnOpeartion(phaseID);
                    ((RadComboBoxEditorElement)(editor).EditorElement).SelectedIndex = 0;

                }


            }
            catch
            {
            }

        }



 void Editor_ValueChanging(object sender, ValueChangingEventArgs e)
        {
            try
            {
                int index = dgridSubParts.CurrentCell.RowIndex;
                dgridSubParts.CurrentRow.Cells["colOperation"].BeginEdit();
              
                if (index == -1)
                {dgridSubParts.Rows.RemoveAt(dgridSubParts.RowCount-1);
                dgridSubParts.CurrentRow.Cells["colOperation"].BeginEdit();
                   // dgridSubParts.CurrentRow = dgridSubParts.Rows[dgridSubParts.RowCount - 2];
                }

            }
            catch
            {
            }
            // dgridSubParts.CurrentColumn = dgridSubParts.Columns["colOperation"];



        }



0
Jack
Telerik team
answered on 28 May 2010, 02:41 PM
Hello Sally Attalla, I am glad to hear that you have resolved this issue and thank you for sharing the solution with the community. If you have other questions, do not hesitate to contact us.

All the best,
Jack
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Sally Attalla
Top achievements
Rank 1
Answers by
Rasha Abdelhameed
Top achievements
Rank 1
Jack
Telerik team
Sally Attalla
Top achievements
Rank 1
Share this question
or