数据网格(可编辑的问题,访问问题)在WPF [英] Datagrid (editable issue, access issue) in WPF

查看:96
本文介绍了数据网格(可编辑的问题,访问问题)在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个DataGrid,如本图所示 - > 的http:// img682 .imageshack.us / img682 / 5109 / datagrid.png

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

在这里假设用户输入数据。在一列,我添加Combobox.Now下,DataGrid不会让我在单元格中输入的数据。 IsReadOnly =假也没有工作,这是给一些编辑模式异常。
所以,我所做的就是,我创建文本块,并在其中如下所示创建组合框和文本框:

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>

使用此用户可以在细胞中添加文字,但我自己,我不开心和我的:(这种方法。利用这一点,我想我将无法访问内容输入,用于其它用途,如节能在某种数据结构网络或DB的.............
我也不能够将内容添加到组合框,使用文本框(上按一下按钮,在<建议href=\"http://stackoverflow.com/questions/2296195/2-quick-wpf-windows-$p$psentation-foundation-questions-on-tabs-and-combo-boxes\">$p$pvious问题),当我用这个code {cmb_act_mf.Items.Add(txt_box.Text); } ...它不会工作的。 ..................如何使Datagrid的编辑?在它的一列组合框,这样它的列表/内容可以通过文本框上点击按钮添加。而且我可以访问,细胞内容物(如用户输入)轻松地存储在DS / DB .....是Datagrid的正确的选择?请帮忙。

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.

在此先感谢这么多。鸭preciate任何帮助,code段将是一个blessing.Thanks。

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

推荐答案

在MS WPF数据网格主要集中围绕数据绑定。尝试创建一个对象绑定到,而不是使用DataGridTemplateColumn,使用DataGridTextColumn和DataGridComboBoxColumn和编辑应该与你的预期。然而,为了得到你需要访问绑定对象的属性的值。

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.

这篇关于数据网格(可编辑的问题,访问问题)在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆