How to programmatically set cell value in DataGridView?

前端 未结 14 884
無奈伤痛
無奈伤痛 2020-11-30 02:05

I have a DataGridView. Some of the cells receive their data from a serial port: I want to shove the data into the cell, and have it update the underlying bound object.

14条回答
  •  粉色の甜心
    2020-11-30 03:01

    If the DataGridView has been populated by DataSource = x (i.e. is databound) then you need to change the bound data, not the DataGridView cells themselves.

    One way of getting to that data from a known row or column is thus:

    (YourRow.DataBoundItem as DataRowView).Row['YourColumn'] = NewValue;
    

提交回复
热议问题