简体   繁体   English

如何使ReadOnly DataGrid中的最后一行可编辑

[英]How to make the last row in a ReadOnly DataGrid editable

I'm using a ReadOnly DataGrid to display some data in my WPF-application. 我正在使用ReadOnly DataGrid在WPF应用程序中显示一些数据。

My question then is. 我的问题是。

How can I make the last row editable ? 如何使最后一行可编辑?

<DataGrid x:Name="dataGrid" AutoGenerateColumns="False" ItemsSource="{Binding Students}" LoadingRow="dataGrid_LoadingRow_1">

private void dataGrid_LoadingRow_1(object sender, DataGridRowEventArgs e)
    {
        if (e.Row.IsNewItem)
            e.Row.IsEnabled = true;
        else
            e.Row.IsEnabled =false;
    }

I have been working in windows forms not wpf and am fairly new to C# so there may be a better way to do this. 我一直在Windows窗体而不是wpf中工作,并且对于C#来说还很陌生,所以可能有更好的方法可以做到这一点。

I encountered a similar problem and to get around it I made the table not read only, and then looped through all of the rows and set them individually to ReadOnly except for the last one. 我遇到了类似的问题,为了解决这个问题,我使表不是只读的,然后遍历所有行并将它们分别设置为ReadOnly(最后一行除外)。 Not the prettiest but it worked. 不是最漂亮,但它起作用。

foreach (DataRow dataRow in dataGridView.Rows)
{
    dataRow.ReadOnly = true;
}

dataGridView.Rows[dataGridView.Rows.Count - 1].ReadOnly = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM