来自DatagridView数据源的临时DataTable(Temporary DataTable from DatagridView datasource)
我有一个数据表,它是从datagridview数据源创建的,并希望对该数据表进行修改,如:
DataTable dt = (DataTable)dataGridView1.DataSource; dt.Remove("xyz");
这会从dt中删除xyz列,但是也会从datagridview的原始数据源中删除它。 但我想将此dt仅用于临时目的,并且不希望将列从原始列中删除。
为什么它们的行为类似于绑定变量,我该如何处理?
I have a datatable which created from a datagridview datasource and want to make modifications on that datatable like:
DataTable dt = (DataTable)dataGridView1.DataSource; dt.Remove("xyz");
This removes the xyz column from dt, well, but removes it from the datagridview's original datasource too. But i want to use this dt for only temporary purposes and not want the column to be removed from original.
Why do they behave like binded variables and how can I handle this?
原文:https://stackoverflow.com/questions/37616853
最满意答案
由于在C ++中实现了迭代器,它是否会发生一些事情
不,这是未定义的行为。 迭代器已变为无效,无法使用。
是因为内存段被宣布为免费使用,但尚未更改?
是的,这就是你观察你所观察到的东西的原因。 但是内存可以被重用于其他东西,或者无法访问 - 你不能依赖任何未定义行为的观察。
Is it something bound to happen due to the implementation of iterators in C++
No, it's undefined behaviour. The iterator has become invalid, and can't be used.
is it because the segment of the memory was declared as free for used, but hasn't been changed yet?
Yes, that's why you observed what you observed. But the memory could be reused for something else, or made inaccessible - you can't rely on any observations of undefined behaviour.
相关问答
更多-
C ++ - 无法通过引用传递迭代器指向的对象(C++ - Cannot pass the object pointed by an iterator by reference)[2022-01-28]
set包含具有唯一值的不可变对象,但goo需要非const引用。 更改goo以获取const引用,使用除集合之外的其他内容,或者创建对象的副本。 只要对象在集合中,就不能对其进行修改,因此无法将其传递给修改(或可以修改)对象值的函数。 A set contains immutable objects with unique values, but goo requires a non-const reference. Either change goo to take a const reference, ... -
从列表中删除迭代器后,为什么保留了迭代器指向的数据(Why is the data pointed by the iterator kept, after deleting it from the list)[2023-07-20]
由于在C ++中实现了迭代器,它是否会发生一些事情 不,这是未定义的行为。 迭代器已变为无效,无法使用。 是因为内存段被宣布为免费使用,但尚未更改? 是的,这就是你观察你所观察到的东西的原因。 但是内存可以被重用于其他东西,或者无法访问 - 你不能依赖任何未定义行为的观察。 Is it something bound to happen due to the implementation of iterators in C++ No, it's undefined behaviour. The iterat ... -
是否安全(记录行为?)删除执行中的迭代器的域(Is safe ( documented behaviour? ) to delete the domain of an iterator in execution)[2021-08-21]
从Python教程 : 修改循环中迭代的序列是不安全的(这只能发生在可变序列类型中,例如列表)。 如果您需要修改正在迭代的列表(例如,复制所选项目),则必须迭代副本。 切片表示法使这特别方便: >>> for x in a[:]: # make a slice copy of the entire list ... if len(x) > 6: a.insert(0, x) ... >>> a ['defenestrate', 'cat', 'window', 'defenestrate'] Fro ... -
每次调用it.next() ,都会获得下一个元素并向前移动光标。 相反,存储实例,执行检查并执行单击,如: WebElement e; while(it.hasNext()) e = it.next(); if(e.getText().equals(cat)) { e.click(); } } Each time you call it.next(), you get the next element AND move the cursor ahead. Inste ...
-
我觉得这相当pythonic。 我只想改为: def parse_data: if isinstance(value, dict): iterator = value.items() elif isinstance(value, list): iterator = enumerate(value) else: return for key, item in iterator: parse_data(value ...
-
一个主要问题是你(显然,你没有提供完整的代码) delete一个对象两次:一次迭代列表A,一次迭代列表B. 主要有三种解决方案: 使用像std::shared_ptr这样的ref-counting智能指针。 推荐的。 你不想使用智能指针的陈述似乎是出于无知,而不是一些愚蠢的经理的要求。 将节点保留在主列表中: 只有当您知道它所在的唯一列表是主列表时才delete节点。 自己实施引用计数: 最简单的方法是再次使用现有的库解决方案,例如boost::intrusive_ptr ,但您所要做的就是在每个节点中精心 ...
-
改变这个: std::list
::const_iterator goop = bob.begin(); 对此: std::list ::const_iterator goop = bob.begin(); 因为你需要指向整数的指针 ,在你的第一个例子中。 Change this: std::list ::const_iterator goop = bob.begin(); to this: std::list ::const_iterator goop = bob ... -
auto midiMessage = queuedNotes.begin(); midiMessage的类型为std::multiset::iterator 。 并且它无法转换为您的类型IMidiMsgExt 。 Iterator是一个与指针行为类似的对象,因此您可以使用取消引用运算符( * )来获取它“指向”的对象。 您也不需要将派生对象强制转换为其基础,这是隐式完成的。 您需要做的就是获取迭代器“指向”的地址以获取指向IMidiMsgExt的指针: SendMidiMsg(&*midiMessage) ...
-
C ++迭代器列表(C++ Iterator List)[2022-04-12]
使用std :: ostringstream而不是std :: cout http://www.cplusplus.com/reference/sstream/ostringstream/ #include.... std::ostringstream names; std::string delimiter = ","; std::list ::const_iterator it = pNames->begin(); if (it != pNames->cend()) ... -
迭代器实现问题(Iterator implementation issues)[2023-07-14]
第一个节点的prev指针是NULL,所以是最后一个节点的下一个指针。 一个接一个的结束current指针将为NULL。 operator-> First node's prev pointer is NULL, so is last node's next pointer. One-past-the-end's current pointer would be NULL. operator->