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

GridViewComboBoxColumn and binding from database

2 Answers 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paweł
Top achievements
Rank 1
Paweł asked on 19 Feb 2014, 09:33 AM
Hello.
I'm having some problems with binding values with autoselect value from database.
My grid looks like:
(...another columns...)
<telerik:GridViewComboBoxColumn UniqueName="groupCol" DataMemberBinding="{Binding groupList}"  DisplayMemberPath="name"  SelectedValueMemberPath="gid" Header="Group" >

</telerik:GridViewComboBoxColumn>

And in code behind:


using (SqlCommand cmd = new SqlCommand("SELECT ISNULL(groupID, 0) as gid, (...other values...) ", conn))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                        {
                            DataTable dt = new DataTable();
                            sda.Fill(dt);
                            cardsDG.ItemsSource = dt.DefaultView;
                            ((GridViewComboBoxColumn)this.cardsDG.Columns["groupCol"]).ItemsSource = getGroups();
                        }
                    }

Method to get groups is just select groupID as gid, name from myTable, and add to List<groupList> with public int gid, public string name.

What I'd like to reach is that, if select return ID = 10, I want to select this element in combobox, if isnull is reached, then nothing is selected.
What I'm doing wrong?

2 Answers, 1 is accepted

Sort by
0
Paweł
Top achievements
Rank 1
answered on 19 Feb 2014, 12:23 PM
Ok. I figured it out, but now need information about that how can I get selected id/name from combobox (it seems to be Lookup element).
                 <telerik:GridViewComboBoxColumn.ItemTemplate>
                        <DataTemplate>
                            
                                <TextBlock Text="{Binding gName}" />
                         
                        </DataTemplate>
                    </telerik:GridViewComboBoxColumn.ItemTemplate>
0
Yoan
Telerik team
answered on 21 Feb 2014, 07:49 AM
Hello Paweł,

You can try to use the SelectionChanged event of GridViewComboBoxColumn as shown in this help article.


Regards,
Yoan
Telerik
Tags
GridView
Asked by
Paweł
Top achievements
Rank 1
Answers by
Paweł
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or