在基于Windows的应用程序中自动填充datagridview中的数据 [英] Automatically fill data in datagridview in windows based application

查看:101
本文介绍了在基于Windows的应用程序中自动填充datagridview中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含4列的datagridview。在第一列中,有一个文本框,值来自checkedlistbox,即在datagridview之外。现在在第二列中有一个组合框,其中,值是手动填充的。在第三列中有文本框,我将填充该值,然后在第四列中,该值将是(Column2 * column3),它将在计算后自动生成。那么如何在第四列自动填充值。请帮助我。

I have a datagridview with 4 columns. In first column,there is a textbox and the value is coming from the checkedlistbox ie outside the datagridview. Now in second column there is a combobox and in that, value is manually filled. And in third column there is textbox and i'll fill the value and after that in fourth column,the value will be (Column2*column3) that is automatically comes after the calculation. So how how can i fill value automatically in column fourth. pls help me.

推荐答案

因为有一个网格,我想你有多行。否则这可能是矫枉过正:



将您的思维方式从以UI为中心的模型转变为面向对象的模型。



所以你有一个具有四个属性的对象。实际上,您有一个具有四个属性的类,您将多次实例化它们。将这些对象分组在一个 BindingList< t> [ ^ ]其中 T 是你的班级。



实现所需的行为(基于前三个属性计算第四个属性)。



将BindingList绑定到Grid,CheckedListBox以及其他任何内容。所有这些UI元素都应该处理相同的数据(这是对象的基础列表)。由于所有UI引起的更改都会影响相同的数据,因此数据的更改会显示在所有绑定的UI元素中。



我不确定,但最终你必须实现 INotifyPropertyChanged [ ^ ]对象的界面。
Since there's a grid, I suppose you have multiple rows in it. Otherwise this could be overkill:

Change your way of thinking from a UI-centric model to an object oriented model.

So you have an object with four properties. Actually, you have a class with four properties that you will instantiate multiple times. Group those objects in one BindingList<t>[^] where T is your class.

Implement the desired behaviour (computation of 4th property based on first three properties).

Bind the BindingList to your Grid, to the CheckedListBox, to whatever. All those UI elements should work on the same data (which is the underlying list of objects). Since all UI-induced changes affect that same data, changes of the data get displayed in all bound UI elements.

I'm not sure, but eventually you have to implement the INotifyPropertyChanged[^] interface for your object.


这篇关于在基于Windows的应用程序中自动填充datagridview中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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