Click here to Skip to main content
14,735,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have used a combobox inside my mylistview to display "ages" of the person where ages is my column name and person is my table name.
But when I am trying to assign dataset object to the datacontext of the combobox, it is raising an exception like "Input string not in correct format".
The datatype of my age column is int. So please help me out.

<GridViewColumn Header="Person Age" >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <ComboBox Name="mycombo" DataContext="{Binding Tables[person_details]}"  Width="100" ItemsSource="{Binding}"

                                                SelectedValue="personname" SelectedValuePath="id" DisplayMemberPath="personname">
                                                                           </ComboBox>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

This is my code
var items = (DataRowView)mylist.Items[i];
                ListViewItem myitem = (ListViewItem)(mylist.ItemContainerGenerator.ContainerFromItem(items));
                ContentPresenter content = FindVisualChild(myitem, 2);
                DataTemplate template = content.ContentTemplate;
                ComboBox mycombo1 = (ComboBox)template.FindName("mycombo", content);
                con = new SqlConnection(@"Data Source=SPARSH121\SQLEXPRESS;Initial Catalog=vinayaka;User ID=sa;Password=sparsh");
                da = new SqlDataAdapter("select personname from person_details", con);
                ds = new DataSet();
                da.Fill(ds);
                mycombo1.DataContext = ds.Tables[0];
Posted
Updated 20-Sep-10 0:29am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900