How To Fix DataGridView Rows Showing Up Without Data

Microsoft .NETThe DataGridView is incredibly helpful for binding data sources to a grid, but sometimes working with it is a bit tricky. If you use the DataGridView control sparingly (or you’re just plain forgetful), you might run into an issue where you can see rows in the grid, but all the cells are empty!

DataGridView Empty Rows

The Problem

Not to worry! If you’re seeing the correct number of rows, you probably just have some visibility problems with the class being used.

In my case, I was trying to bind a list of proxies (List) like this:

private void BindProxyGrid(IList proxies)
{
    var proxiesBindingList = new BindingList(proxies);
    dgvProxies.DataSource = proxiesBindingList;
}

And my proxy class looked something like this:

public class Proxy
{
    public string Ip;
    public int Port;
}

The Solution

So why didn’t it work? Because the DataGridView requires properties and I was using public fields. Updating the class to use properties fixed the problem!

public class Proxy
{
    public string Ip { get; set; }
    public int Port { get; set; }
}

It works!

DataGridView Filled Rows

The Lesson Learned

If you’re using a BindingList with your DataGridView, you may need to adjust the visibility for any class members you want to display in the grid; for example, the DataGridView can’t access public fields or properties marked internal.

Happy coding!

Google Plus API

Gplus IconGoogle hasn’t made any official announcements regarding a public API, but there is already a mailing list you can sign up for that will let you know when one is available. If you’re a developer and you’re eager to get hacking on the Google Plus API, be sure to sign up! Knowing Google we’ll see an API released in the near future (though I suspect they still have quite a few features and bug fixes to put out first)!