views:

348

answers:

1

I created a Datagrid, as shown in this figure --> http://img682.imageshack.us/img682/5109/datagrid.png

where user is supposed to enter data. In one of columns, I added Combobox.Now, the Datagrid won't allow me to enter data in the cells. IsReadOnly="False" was also not working, it was giving some "EditMode exception". So, what I did was, I created textblock and within it created combobox and textbox as shown here:

 <toolKit:DataGrid
                                 Width="725"
                                 Height="100" 
                                 HeadersVisibility="Column" 
                                 Focusable="True"
                                 RowDetailsVisibilityMode="Visible" 
                                 Background="#FF98A4B2"  x:Name="mf" >

                    <toolKit:DataGrid.Columns>
                        <toolKit:DataGridTemplateColumn Header="Ssss" Width="55">
                            <toolKit:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock>
                         <TextBox x:Name="mf_step" Width="50"/>
                        </TextBlock>
                                </DataTemplate>
                            </toolKit:DataGridTemplateColumn.CellTemplate>
                        </toolKit:DataGridTemplateColumn>
                        <toolKit:DataGridTemplateColumn Header="Aaaaa" Width="100">
                            <toolKit:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock>
                                      <ComboBox x:Name="cmb_act_mf" ToolTip="Choose Actor" Width="95" IsEditable="False">
                                      <ComboBoxItem Content=""></ComboBoxItem>
                                      <ComboBoxItem Content="Uuuu" IsSelected="True"></ComboBoxItem>
                                      </ComboBox>
                                    </TextBlock>
                                </DataTemplate>
                            </toolKit:DataGridTemplateColumn.CellTemplate>

                        </toolKit:DataGridTemplateColumn>

Using this user can add text in the cells, BUT I myself, am not happy with this approach of mine :( . Using this, I think I won't be able to access content entered, for another use, like saving in some sort of Datastructure or DB............. Nor am I able to add content to the combobox, using text box(on button click, as suggested in previous question), when I use this code { cmb_act_mf.Items.Add(txt_box.Text); } ... it won't work either. ..................How to make Datagrid editable? with combo box in one of it's columns, such that it's list/content can be added through textbox on button click. And I can access, cell contents(where user enters) with ease to be stored in DS/DB.....Is Datagrid right choice? Please help.

Thanks so much in advance. Appreciate any help, code snippet will be a blessing.Thanks.

A: 

The MS WPF datagrid is focused largely around data binding. Try creating an object to bind to, and instead of using DataGridTemplateColumn, use DataGridTextColumn and DataGridComboBoxColumn and the editing should be as you expected. However to get the values you'll need to access the properties on the bound object.

thedesertfox