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

How to get GridViewComboBoxColumn selectedItem

8 Answers 479 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Khoren
Top achievements
Rank 1
Khoren asked on 22 Apr 2017, 09:05 PM

Hi.

I have a RadGridView which has a GridViewComboBoxColumn. ComboBoxColumn.DataSource  is an array of Products. Product is an object that has a few properties like Id, Name, and so on. How i can get ComboBoxColumn selected item?

I have tried figure it out by this way
radGridView1.Rows[index].Cells["ComboBoxColumn Name"].Value but it returns only string, not Product object

Can you help me figure it out?

8 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 24 Apr 2017, 08:20 AM
Hi ,

Thank you for writing.

The editor is only accessible while the cell is beeing edited. And only the selected value is stored. This is why you will need to use this value and manually retrieve the business object from the data source of the column.

I hope this helps.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Khoren
Top achievements
Rank 1
answered on 24 Apr 2017, 08:51 AM

Hi Dimitar.

Thank you for your answer.

I have a one more question about column sorting.

I have an another RadGridView that have a BindingSource typeof(Product). when i click in column header columns sorting works only on primitive types. Let me say if my Product object has a Category object which is in grid appears in TextBoxColumn and have DataType Category, i can't sort it by clicking in Category Column. 
0
Accepted
Dimitar
Telerik team
answered on 24 Apr 2017, 11:54 AM
Hello ,

Your business object should implement the IComparable interface. Here is a simple example:
class MyClass : IComparable
{
  public  string Text { get; set; }
 
    public int CompareTo(object obj)
    {
        return (this.Text.CompareTo(obj.ToString()));
    }
    public override string ToString()
    {
        return this.Text;
    }
}

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Khoren
Top achievements
Rank 1
answered on 24 Apr 2017, 05:07 PM

Hi Dimitar, thank you for solution. it's working.
Now i have another problem with GridViewTextBoxColumn. Im my RadGridView i have a GridViewTextBoxColumn and its MultiLine property set to true. What exactly i want to do... When i editing the cell of GridViewTextBoxColumn and press Enter button I want to add some text into cell and keep it in Edit mode.

I have tried to handle RadGridView.KeyPressed and KeyDown event. but they are firing only when cell is already edited.
In code language i want to do similar with this.
private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)

{

if (e.Column.Name == "SerialNumbers")

    {

radGridView1.CurrentCell.Value = radGridView.CurrentCell.Value.Tostring + Enviroment.NewLine;

radGridView.CurrentCell.BeginEdit();

    }

}

0
Khoren
Top achievements
Rank 1
answered on 24 Apr 2017, 07:39 PM
Also, how can i set Text for GridViewComboBoxColumn like DropDownList.Text property
0
Dimitar
Telerik team
answered on 25 Apr 2017, 09:48 AM
Hi Khoren,

Make sure that the AcceptsReturn property of the column is set:
var col = radGridView1.Columns[1] as GridViewTextBoxColumn;
col.AcceptsReturn = true;
col.Multiline = true;

You can use the CellEditorInitialized event to set the editor value:
private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    if (e.Column.Name == "Name")
    {
        e.ActiveEditor.Value = "test";
    }
}

I hope this helps.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Khoren
Top achievements
Rank 1
answered on 25 Apr 2017, 10:09 AM
Hello Dimitar. You solution for ComboBoxCell text is working only when user do click on the cell
0
Accepted
Dimitar
Telerik team
answered on 25 Apr 2017, 11:33 AM
Hello Khoren,

I am not sure why the appropriate text is not displayed. In general, it should be displayed automatically. Perhaps it would be better to open e new thread for this and send us the code for the column initialization and a screenshot of the actual result.

In addition, please make sure that the DisplayMember/ValueMember properties are set correctly.  

I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Khoren
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Khoren
Top achievements
Rank 1
Share this question
or