如何在代码中将Silverlight 3 DataGridCell置于编辑模式?

如何在代码中将Silverlight 3 DataGridCell置于编辑模式?,第1张

概述我希望能够在Silverlight 3.0 DataGrid中选择一个特定的单元格并将其置于编辑模式.我可以使用VisualTreeManager来定位单元格.如何切换到编辑模式? 每个DataGridCell在VisualTreeManager中都是这样的: System.Windows.Controls.DataGridCell System.Windows.Contr 我希望能够在Silverlight 3.0 DataGrID中选择一个特定的单元格并将其置于编辑模式.我可以使用VisualTreeManager来定位单元格.如何切换到编辑模式?

每个DataGrIDCell在VisualTreeManager中都是这样的:

System.windows.Controls.DataGrIDCell            System.windows.Controls.GrID              System.windows.Shapes.Rectangle              System.windows.Controls.ContentPresenter                System.windows.Controls.TextBlock              System.windows.Shapes.Rectangle              System.windows.Shapes.Rectangle

使用包含我要编辑的文本的TextBlock.

更新

按照@AnthonyWJones的建议,这是我尝试使用BeginEdit()的方法.

我想保持简单,所以我想我会在第一行选择一列.即使这证明超出了我的SL知识!最后,我通过创建一个名为firstRow的字段来保存第一行:

private DataGrIDRow firstRow;

向DataGrID添加了一个LoadingRow处理程序:

LoadingRow="computersDataGrID_LoadingRow"

private voID computersDataGrID_LoadingRow(object sender,DataGrIDRowEventArgs e){    if (this.firstRow == null)        this.firstRow = e.Row;}

然后向面板添加一个按钮以触发编辑:

private voID button_Click(object sender,RoutedEventArgs e){    this.dataGrID.SelectedItem = this.firstRow;    this.dataGrID.CurrentColumn = this.dataGrID.Columns[4];    this.dataGrID.BeginEdit();}

我单击按钮并选择了正确的单元格,但它不会在单元格上进行编辑.需要手动点击才能实现这一目标.

解决方法 我不确定为什么你需要使用VisualTreeManager找到DataGrIDCell,我也不知道你现在如何正确地开始编辑.您可以简单地将单元格的视觉状态设置为编辑.

visualstatemanager.GoToState(myDataGrIDCell,"Editing",true);

当你做上面这样的事情时,我不确定网格是如何表现的.如果您需要DataGrID来帮助您将更改还原到行,您可能会发现有点梨形状.

“标准”方法是将DataGrID SelectedItem属性设置为行所表示的项,将CurrrentColum属性设置为DataGrIDColumn对象,该对象表示找到该单元格的列.然后调用BeginEdit方法.

总结

以上是内存溢出为你收集整理的如何在代码中将Silverlight 3 DataGridCell置于编辑模式?全部内容,希望文章能够帮你解决如何在代码中将Silverlight 3 DataGridCell置于编辑模式?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1000989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存