Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Databinding of Count (of a DataGridView) to a Label

$
0
0

I am trying to bind the count of a DataGridView to a Label.

The following code results in a runtime error saying that it cannot be bound to the Count property.

Binding binding = new Binding("Text", datagridview, "Rows.Count", true);
binding.Format += (sender, e) => e.Value = string.Format("{0} items", e.Value);
label.DataBindings.Add(binding)

The datasource of the DataGridView is a BindingList (to be more precise, a derived version of the BindList which is sortable and filterable). I also tried to bind to the Count property of the BindingList, but this also failed.

I googled the following solution which somehow wraps the list, but this does not work for me:
http://stackoverflow.com/questions/639894/how-to-bind-a-list-count-to-a-label-in-winforms


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>