WPF可编辑数据网格 [英] WPF Editable Datagrid

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

问题描述

您好。

文本框中的用户输入行数和列数,我必须使用此大小创建可编辑的DataGrid。我该怎么做?



 DataGrid table =  new  DataGrid( ); 
for int i = 0 ; i < 5 ; i ++)
{
table.Columns .Add( new DataGridTextColumn());
table.CanUserAddRows = true ;
table.CanUserDeleteRows = true ;
table.IsReadOnly = false ;
table.Items.Add( new DataGridTextColumn());
}



使用此代码我创建了我需要的大小的表,但是当我尝试编辑单元格时,我得到了editItem不允许错误。



如果我执行此代码我会得到带有TextBox字段的列。

 DataGrid table =  new  DataGrid(); 
列表< TextBox> tableData = new 列表< TextBox>( 5 );
table.ItemsSource = tableData;



任何帮助?

解决方案

< blockquote>下面我提到你的参考链接请检查..



WPF DataGrid实例 [ ^ ]



如果您找到解决方案然后标记为已回答..



谢谢



快乐编码....



这是关于你的第二个查询的解决方案..



是的你是对的......是的,这是可能的..



  public  覆盖  void 执行(对象参数)
{
var context =参数 as GenerateColumnContext;
DataGridTextColumn column = new DataGridTextColumn();
if (context.PropertyName == 国家/地区
{
column.Header = 国家/地区的标头< /跨度>;
}
context.Result = column;
}





这可以帮助你进一步...



谢谢



如果您得到与此帖相关的答案,请标记为已回答..


Hello.
User input in textboxs number of rows and columns and I have to create editable DataGrid with this size. How can I do this?

DataGrid table = new DataGrid();
for (int i = 0; i < 5; i++)
{
    table.Columns.Add(new DataGridTextColumn());
    table.CanUserAddRows = true;
    table.CanUserDeleteRows = true;
    table.IsReadOnly = false;
    table.Items.Add(new DataGridTextColumn());
}


With this code I create table with size that I need, but when I try to edit cell, I''he got "editItem not allowed" error.

if I do this code I''he got columns with TextBox fields.

DataGrid table = new DataGrid();
List<TextBox> tableData = new List<TextBox>(5);
table.ItemsSource = tableData;


Any help?

解决方案

Below i mention link for your reference please check it..

WPF DataGrid Practical Examples[^]

if you finding solution then mark as answered..

Thanks

Happy coding....

This is solution regarding your second query..

yes you are right....yes it is possible..

public override void Execute(object parameter)
{
    var context = parameter as GenerateColumnContext;
    DataGridTextColumn column = new DataGridTextColumn();
    if (context.PropertyName == "Country")
    {
        column.Header = "header for Country";
    }
    context.Result = column;
}



May be this can help you further...

Thanks

If you getting your answer related to this post then please mark as answered..


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

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