0

The closest I have come to finding the solution I need is through the Microsoft Website itself (not all that helpful really) and from this question: How to dynamically assign Datagridview cell values based on data from my database?

So I have this DataGridView object which has a bound DataTable. I have bound the data table like this

GridMemory.DataSource = dtMemory;

I want to perform operations with the DataTable rows. I'm not using this to link to a database, instead, I am using this as a cache of data that both the user and the computer can manipulate to represent the von neumann architecture of a micro-processor. So I have created an array of MemoryRow objects and given each a pointer to a corresponding DataRow from the DataTable. I then try to dynamically alter the data from within the MemoryRow object like this:

public void UpdateGUI() {
    dataRow.SetField(1, data);
    dataRow.SetField(2, opcode);
    dataRow.SetField(3, value);
    dataRow.AcceptChanges(); // the commands above are not working, maybe this will help?
    dataRow.SetModified(); // that also didn't work, maybe it needs to set a flag then have an event fire?
}

What am I doing wrong or missing?

Timothy Eckstein
  • 307
  • 1
  • 2
  • 10
  • Well, there is nothing obviously wrong in this part of the code. Other than: 1. dataRow.AcceptChanges() and dataRow.SetModified() are not really necessary. 2. Are you quite sure the column indexes you use in SetField should not start with 0? Also it makes code more readable if you use column names in some form, the easiest way would be just indexing them via strings, like this: dataRow["SOME_FIELD"] = value1; dataRow["SOME_OTHER_FIELD"] = value2; – Avo Nappo Oct 01 '17 at 11:04
  • You don't need pointers. The DGV row numbers are the same as the dtMemory datatable row numbers. – jdweng Oct 01 '17 at 11:25

0 Answers0