FrancineTaylor
asked on
DataGridView: manual change in databound object doesn't trigger redisplay of value in grid
I have two State columns in my DataGridView, the first is the abbreviation (example: "TX") and the second is the name (example: "Texas"). The short name column is a combo box column, the second is a display-only text.
In the class which is bound to the grid, here are the state properties:
public string GridColumn3 {
get { return column3; }
set {
// if we are changing the state
if (!value.Equals(this.column 3)) {
state = cState.FindState(value.ToS tring()); // returns a state object
this.column3 = state.ShortName;
this.column4 = state.LongName;
}
}
}
public string GridColumn4 {
get { return column4; }
}
Here is the problem; the value in column4 is changed by the column3 property, but that change doesn't show up visually in the grid until the user enters the cell. How can I force the column4 cell to redisplay after the column3 property change occurs?
In the class which is bound to the grid, here are the state properties:
public string GridColumn3 {
get { return column3; }
set {
// if we are changing the state
if (!value.Equals(this.column
state = cState.FindState(value.ToS
this.column3 = state.ShortName;
this.column4 = state.LongName;
}
}
}
public string GridColumn4 {
get { return column4; }
}
Here is the problem; the value in column4 is changed by the column3 property, but that change doesn't show up visually in the grid until the user enters the cell. How can I force the column4 cell to redisplay after the column3 property change occurs?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for a very elegant solution!
ASKER
In any case, just FYI, I just Googled a post which had this suggestion:
// This forces the row to repaint itself after any value is changed in the row
int oldRowIndex = -1;
private void dataGridView1_CurrentCellC
if (oldRowIndex != -1) {
this.dataGridView1.Invalid
}
oldRowIndex = this.dataGridView1.Current
}
...which also works, but your solution is much more efficient and elegant.