简体   繁体   中英

C# DataGridView Row add dataGridView button text not change

I am reading xml file in winform and displaying data in DataGridView DataGridView read in xml has a button, and when the button is clicked, the button's text is changed.

DataGridViewButtonCell btnStart = null;
btnStart = (DataGridViewButtonCell)(DataGridView.Rows[e.RowIndex].Cells[0]);
var btnType = btnStart.Value.ToString();
btnStart.UseColumnTextForButtonValue = false;

In this result I try to re-read the XML and append the ROW

DataGridView.DataSource = dataSet.Tables[0];

Is there a way to add ADD to the DataGridView without changing the text of the button in the DataGridView that is shown?

This line of code: DataGridView.DataSource = dataSet.Tables[0];

Doesn't read a row, it resets the entire DataGridView , which is why the button changes. If you want to append a row, then add a row to the Table the DataGridView is displaying, don't replace the whole thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM