开发者

I need a row Added event for a DataGridView

开发者 https://www.devze.com 2022-12-29 15:39 出处:网络
What i want t开发者_运维问答o do is set the background of a row based on some criteria, but the datagrid will be fairly large so i don\'t want to have to loop over all the rows again.The rows get crea

What i want t开发者_运维问答o do is set the background of a row based on some criteria, but the datagrid will be fairly large so i don't want to have to loop over all the rows again. The rows get created me doing something like "myDataGridView.DataSource = MyDataSource, so the only way i can think to edit rows is by using an event.

there is a rows added event, but that gives me a list of rows that i'd have to iterate over.

Thanks in advance for any help.


So where is your problem?

You have to put your finger on each row for a minimum of one time. So what is the difference if you get in a RowAdded event a single row or a bunch of them? In the case of a bunch you also get every line only one time, but with lesser events, which could also result in a faster code (but to be sure i would do profiling on that!).


While this may not answer your question directly, did you consider assigning the datasource while it is still empty, and then populate the datasource with data. In this case, if for example you are using a binding list, you can make use of the event provided by the bindinglist to determine if a new item was added or not


I'm using the RowStateChanged event now. It fires more often then i need, but thats not really a problem. I found something really odd with this one. It looked like if set the background color of the first row, it changed all the rows. I can't figure out why it did that, but i just added an else statement to force everything else to be white.

Its good enough for me. Thanks for the help guys.


It's been a while, but I think I used the DataGridView.RowPostPaint event in a few situations where I needed just that.

From the event args passed into the event handler, you have access to the RowIndex, allowing you to get to the Row object, from which you can reference the DataBoundItem etc.

Please look it up and see if it does what you need.

HTH

0

精彩评论

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

关注公众号