开发者

Winform DataGrid with detail, what is the best way

开发者 https://www.devze.com 2023-04-01 03:51 出处:网络
I\'m pretty new to c# and Winforms and I\'m wondering what is the best approach to the following screen design.

I'm pretty new to c# and Winforms and I'm wondering what is the best approach to the following screen design. I have a window that contain a Datagrid wich would be read-only. Beneath the grid, I have the detail of the records in differents fields (textbox, combobox, checkbox). What I want is that when the user click on an item in the datagrid, the data will be shown in the detail fields. That par开发者_JAVA技巧t is pretty easy, but I want to be able to update the fields automatically, wich means, I would prefer to not have to press a Save button. Let's say that I click an item in the datagrid, change some value in the detail fields and the I click on another item in the datagrid, then I also want to perform some validation and calculation before the record get updated. What I was thinking at first was to get the button for "new", "edit", "save" action and lock and unlock the fields accordingly and keep a flag to know if i need to insert or update the data, but then I realized that I would prefer to not have thoses button and have the save performed automatically. Is there any sample somewhere that does what I want? Also, would you guys using the built-in databinding functunality or just use a dataset object in code?


Pretty common scenario.

On selected row change of grid you know which datarow you shoul bind to the other controls. when same event happens again you validate and save or cancel in case of errors.


You can make use of DataGridView.CellEndEdit Event to get the new value and DataGridView.CellBeginEdit event to get the old value and update your data if there is any change

0

精彩评论

暂无评论...
验证码 换一张
取 消