我以编程方式填充datagridview行,但是当我将行留空时 [英] I fill datagridview rows programmatically but when I leave row it blank

查看:76
本文介绍了我以编程方式填充datagridview行,但是当我将行留空时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码是

dgShop.Rows [i] .Cells [2] .Value = ds1.Tables [0] .Rows [0] .ItemArray [0] .ToString();

然后



code is
dgShop.Rows[i].Cells[2].Value = ds1.Tables[0].Rows[0].ItemArray[0].ToString();
and then

private void dgShop_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2 && e.RowIndex >= 0)
            {
                if (e.RowIndex == 0)
                {
                    dgShop.Rows[e.RowIndex].Cells[3].Value = "1";
                    dgShop.Rows[e.RowIndex].Cells[4].Value = dgShop.Rows[e.RowIndex].Cells[2].Value;
                }
                else
                {
                    dgShop.Rows[e.RowIndex].Cells[3].Value = (Convert.ToInt32(dgShop.Rows[e.RowIndex - 1].Cells[4].Value) + 1).ToString();
                    dgShop.Rows[e.RowIndex].Cells[4].Value = (Convert.ToInt32(dgShop.Rows[e.RowIndex].Cells[2].Value) + Convert.ToInt32(dgShop.Rows[e.RowIndex - 1].Cells[4].Value)).ToString();
                }

            }
        }

It done but it is automatic blank

推荐答案

1。您的XAML代码是否包含引用您的VM的DataContext语句?

1. Does your XAML code contain a DataContext statement that references your VM?
<window ...="">
    <grid>DataContext="{StaticResource vm}">
        <!-- more stuff goes here -->
    </grid>
</window>



2.您的VM是否实现了INotifyPropertyChanged界面?


2. Does your VM implement the INotifyPropertyChanged interface?

class FooVM : INotifyPropertyChanged
{
    #region Implementation of INotifyPropertyChanged

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

    // more stuff goes here
}





3。在每次更改为dgShow后,您是否使用XAML名称dgShow调用PropertyChanged事件处理程序?



3. After each change to dgShow, are you calling the PropertyChanged event handler with the XAML name of dgShow?

//  call this with the property name after every change!
public void NotifyPropertyChanged(string propertyName = "")
{
    if (PropertyChanged != null)
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}





XAML模型将显示模型与基础数据模型分开。更改显示时,不仅必须通知数据模型,还必须在更改数据模型时通知显示。



The XAML model separates the display model from the underlying data model. Not only must the data model be notified when the display is changed, but the display must be notified when the data model is changed.


这篇关于我以编程方式填充datagridview行,但是当我将行留空时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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