c# - Adding rows to DataGridView programmatically -
i have datgridview
add together new rows. first column of every row image indicates whether rest of row has been completed. maintain track of each row has list-like object attached counts number of completed fields, changes image if plenty fields have been completed. works expected when user adding rows in gui, run problems when seek add together new rows programmatically.
when new row created, datagridviewimagecell
first column added custom class keeps track of completed fields.
here code add together new row:
//initiate new row object[] buffer = new object[13]; buffer[0] = nullimage; //a blank image (int = 1; < buffer.length; i++) { buffer[i] = string.empty; } rowid = datagridview1.rows.add(buffer);
here rowadded
code:
private void datagridview1_rowsadded(object sender, datagridviewrowsaddedeventargs e) { datagridviewimagecell tmp = (datagridviewimagecell)datagridview1.rows[datagridview1.rowcount - 1].cells[0]; datagridview1validatefields.addrow(tmp); //custom class maintain track of completed fields }
the custom class contains list of datagridviewimagecells
dgvic; here its' addrow
method:
private list<object> dgvic = new list<object>(); public void addrow(datagridviewimagecell p) { items.add(new list<int>());//list of ints maintain track of completed fields dgvic.add(p); }
when come in debugger (while adding rows programmatically) can see each time add together new row datagridviewimagecells
stored in dgvic
recent row. instance after adding 3 rows, i'd expect 3 datagridviewimagecells
rows 0, 1 , 2; of them row 2.
it looks me rowcount
still tied each datagridviewcell
, , rowcount
increments cell changes. if case though, how come works through gui? have ideas?
change yours addedrows
event follows:
private void datagridview1_rowsadded(object sender, datagridviewrowsaddedeventargs e) { int index = e.rowindex; (int = 0; < e.rowcount; i++) { datagridviewimagecell tmp = (datagridviewimagecell)datagridview1.rows[index].cells[0]; datagridview1validatefields.addrow(tmp); index++; } }
c# .net datagridview
No comments:
Post a Comment