简体   繁体   English

如何使用GridView在ListView中动态更改单元格值

[英]How to change cell value dynamically in ListView with GridView

I have used the GridView inside the ListView. 我已经在ListView中使用了GridView。 I want to dynamically change a cell value. 我想动态更改单元格值。 For example, there is a column named "Time", I wanna to change this value when something happens. 例如,有一列名为“时间”的列,我想在发生某些情况时更改此值。 I can find and get the cell (eg od.Time as in following codes), but can not change its value . 我可以找到并获取该单元格(例如,以下代码中的od.Time ), 但是不能更改其value Some codes like this where ObjectData is the class for all ListView columns. 像这样的一些代码,其中ObjectData是所有ListView列的类。

for (int i = 0; i < 5; i++)
{
      ObjectData od = (ObjectData)objectListView.Items[i];
      if (od.UserName == "Tom")
      {
          od.Time = DateTime.Now.ToString();
      }
 }

If the your listview is bound to a data source you'll need to change the data source's data, not the listview's contents. 如果您的列表视图绑定到数据源,则需要更改数据源的数据,而不是列表视图的内容。 It should then update the listview. 然后,它应该更新listview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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