双击datagrid行以在WPF C#中打开编辑表单 [英] Double click datagrid row to open edit form in WPF C#

查看:264
本文介绍了双击datagrid行以在WPF C#中打开编辑表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双击datagrid行以在wpf中打开编辑表单#





i想要打开选定的行网格详细信息到另一个表单。



公司editcompany = new公司();



DataRowView drv = dgvCommon.SelectedItem as DataRowView;



editcompany.cmpID = Convert.ToInt32(drv [CompanyId]。ToString());



NavigationService navService = NavigationService.GetNavigationService(this);



navService.Navigate(editcompany);



我尝试了什么:



i在此行中出现错误,如

对象引用未设置为实例一个对象。





editcompany.cmpID = Convert.ToInt32(drv [CompanyId]。ToString());

double click datagrid row to open edit form in wpf c#


i want to open selected row grid details to another form with filling.

Company editcompany = new Company();

DataRowView drv = dgvCommon.SelectedItem as DataRowView;

editcompany.cmpID = Convert.ToInt32(drv["CompanyId"].ToString());

NavigationService navService = NavigationService.GetNavigationService(this);

navService.Navigate(editcompany);

What I have tried:

i got error in this line like
Object reference not set to an instance of an object.


editcompany.cmpID = Convert.ToInt32(drv["CompanyId"].ToString());

推荐答案

错误信息非常简洁,并清楚地告诉您有什么问题。你的对象是null,使用它,

Error message is pretty much neat and tells you clearly what is wrong. Your object is null, use this,
editcompany.cmpID = Convert.ToInt32((drv["CompanyId"] ?? String.Empty).ToString());



您还可以使用简单的 if ... else 块来检查之前的空值。



代码执行中的空缺误是什么 [ ^ ]

c# - 在ToString()之前检查null - Stack Overflow [ ^ ]

C#方法以防止字符串中的空引用 - 代码审查堆栈交换 [ ^ ]


You can also use a simple if...else block to check for null values prior.

What Is A Null Error in Code Execution[^]
c# - Checking for null before ToString() - Stack Overflow[^]
C# approach to prevent null references in strings - Code Review Stack Exchange[^]


这篇关于双击datagrid行以在WPF C#中打开编辑表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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