C# 在GridControl中添加新行

C# 在GridControl中添加新行,c#,add,rows,gridcontrol,C#,Add,Rows,Gridcontrol,我想添加一行,当我把日期放在我的文本编辑,自动日期添加到我的gridcontrol,但我不知道你怎么帮我请 我的代码是: private void mTxtDateEditFchIni_EditValueChanged(object sender, EditValueChangedEventArgs e) { try { DateTime fechaIni = Convert.ToDateTime(

我想添加一行,当我把日期放在我的文本编辑,自动日期添加到我的gridcontrol,但我不知道你怎么帮我请

我的代码是:

private void mTxtDateEditFchIni_EditValueChanged(object sender, EditValueChangedEventArgs e)
        {
            try
            { 
                DateTime fechaIni = Convert.ToDateTime(mTxtDateEditFchIni.Text);
                string anio = (fechaIni.Year).ToString();
                string year = (fechaIni.Year + 1).ToString();
                string month = (fechaIni.Month).ToString();
                string day = (fechaIni.Day - 1).ToString();
                DateTime fechaFin = Convert.ToDateTime(day + "/" + month + "/" + year);
                mTxtDateEditFchFin.Text = fechaFin.ToShortDateString();
                mtxtdscConfPer.Text = "Periodo " + anio + " - " + year;
                DataTable tblGrid = new DataTable();
                foreach (GridColumn col in mDetalle_grdctl.Columns)
                {
                tblGrid.Columns.Add();
                }
                string[] rwTable = new string[tblGrid.Columns.Count];
                rwTable[0] = fechaIni.ToShortDateString();
                rwTable[1] = fechaFin.ToShortDateString();

                for (int i = 2; i < rwTable.Length; i++)
                {
                    rwTable[i] = "1";
                }
                tblGrid.Rows.Add(rwTable);
                mDetalle_grdctl.ItemsSource = tblGrid;

                mDetalle_grdctl.View.IsEnabled = true;

                mDetalle_grctlvie.NewItemRowPosition = NewItemRowPosition.Bottom;
                mDetalle_grctlvie.MoveLastRow();
                mDetalle_grdctl.View.MoveLastRow();
                mDetalle_grdctl.View.AllowEditing = true;
                movar_isupdatemod = false;

            }
            catch (Exception ex)
            {
                DXMessageBox.Show(ex.Message);
            }            
        } 
private void mTxtDateEditFchIni\u EditValueChanged(对象发送方,EditValueChangedEventArgs e)
{
尝试
{ 
DateTime fechaIni=Convert.ToDateTime(mTxtDateEditFchIni.Text);
字符串anio=(fechaIni.Year).ToString();
字符串year=(fechaIni.year+1).ToString();
字符串month=(fechaIni.month).ToString();
字符串day=(fechaIni.day-1).ToString();
DateTime fechaFin=转换为.ToDateTime(天+“/”+月+“/”+年);
mTxtDateEditFchFin.Text=fechaFin.ToShortDateString();
mtxtdscConfPer.Text=“Periodo”+anio+“-”年;
DataTable tblGrid=新DataTable();
foreach(mDetalle_grdctl.列中的GridColumn列)
{
tblGrid.Columns.Add();
}
string[]rwTable=新字符串[tblGrid.Columns.Count];
rwTable[0]=fechaIni.ToShortDateString();
rwTable[1]=fechaFin.ToShortDateString();
for(int i=2;i
不要在WPF中操作过程代码中的UI元素。这就是XAML的用途。为此创建一个合适的视图模型。这是我的问题,我的朋友,我无法创建视图模型,我不知道如何创建我已经在你的“如何使用数据绑定”中向你展示了。HighCore你的电子邮件兄弟是什么?请在我的Stackoverflow配置文件中查看