TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
shen chang
NA
2
0
delete last row have exception
Dec 19 2014 5:54 PM
A winform has a datagridview gui, it has 5 columns
//I add 3 rows and the try to delete the last row, got exception:
int k=0;
while (k < 3)
{
// add 3 rows
DataGridViewRow row = new DataGridViewRow();
row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
int i= 0;
//dup the first row
foreach (DataGridViewCell cell in dataGridView1.Rows[0].Cells)
{
row.Cells[i].Value = cell.Value;
i++;
}
dataGridView1.Rows.Add(row);
k++;
}
//give them values
for (int i = 0; i < 3; i++)
{
for(int j = 0;j<dataGridView1.ColumnCount;j++)
{
dataGridView1[j, i ].Value = j.ToString() + ":" + i.ToString();
}
}
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
//this got exception, but I can delete second row and first row
dataGridView1.Rows.RemoveAt(dataGridView1.RowCount-1);
Reply
Answers (
2
)
oledb c# code to auto generated ID in a textbox
Duplicate datagridview columns creating