Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

c# - DataGridView CheckBox column doesn't apply changes to the underlying bound object

I have a list of Record objects that serve as rows in my DataGridView. Each Record has a new bool value Helped. Sure enough, this new value shows up as check mark in my form.

As it stands currently, when this box is checked it doesn't seem to change the value of Helped bool in the corresponding Record.

Is there some sort of read-only property I need to change? How do I pass a click on my form back as a change in value of its DataSource?

Edit: I've found the System.Windows.Forms.DataGridViewEditMode.EditOnEnter property, but I'm still not seeing my Record.Helped property get updated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As it stands currently, when this box is checked it doesn't seem to change the value of Helped bool in the corresponding Record.

The changes which you make on a cell of DataGridView, doesn't commit immediately to the data source until you finish editing the cell, then changes will be pushed to data source. If for any reason you want to push changes sooner, you can call:

dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);

For example you can do that in CellContentClick event of your DataGridView to push check box value to the underlying property of data source.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...