C # dataset index No Value Solution

Source: Internet
Author: User
C # dataset index No Value SolutionReply

When datsset is bound to the datagrieview, when the dataset data is refreshed, the bug is often found: index 0 has no value or index (INT) X has no value indexoutofrangeexception.


I made an afternoon yesterday and found the cause of the bug:
When data exists in the dview, the first row is selected by default. When we clear the data in the dataset, NO content exists in the datagridview, but the datagrieview is still selecting the first row, so the index 0 has no value. If the second row is selected and the data in dataset is cleared, no value of Index 1 is returned.
Solution:
Before clearing the data of the dataset, deselect all rows in the datagridview.
[Code]
Foreach (datagridviewrow row in datagridview1.rows)
{
Row. Selected = false;
}

[/Code]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.