Click here to Skip to main content
15,662,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone tell why this datagrid doesn't show the new row, row?

public ObservableCollection<string> PasswordGuesses { get { return _passwordGuesses ?? (_passwordGuesses = new ObservableCollection<string>() { "password" }); } }

<DataGrid Grid.Row="0" AutoGenerateColumns="False" ItemsSource="{Binding PasswordGuesses}" CanUserAddRows="True">
        <DataGridTextColumn Header="Password" Binding="{Binding .}" MinWidth="150"/>
        <!--<DataGridTemplateColumn Header="Operations">
                    <Button Content="-" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid}, Path=DataContext.DeletePasswordCommand}" CommandParameter="{Binding .}" />
Updated 8-Apr-11 6:53am
[no name] 8-Apr-11 12:59pm    
Tarun, did you add anything meaningful to this code?
[no name] 8-Apr-11 12:59pm    
What's the </string> ?

1 solution

You either need to set AutoGenerateColumns to true or provide a property that the DataGridTextColumn can bind to. In the latter case, you will need to define a model with one property, create instance of that model, add them to the collection and display them.
Share this answer
[no name] 8-Apr-11 13:02pm    
How can I set the header of the column if I autgenerate, though?
[no name] 8-Apr-11 13:02pm    
And why isn't a string a model?
Abhinav S 8-Apr-11 13:11pm    
Ok it is in a way - try Binding="{Binding Path=/}".
[no name] 8-Apr-11 13:16pm    
didn't work
Abhinav S 8-Apr-11 13:23pm    
AFAIK, you need to bind to a property name. I thought / might work, but apparently, it does not work in a DataGridTextColumn.

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