Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

can I bind a datagrid to a ring buffer?

$
0
0

I have a Table of length 50 (for example) (it is an Observable Collection), and the entries are objects containing strings Index and Entry. The Index field contains strings holding integers from 0 to 49.

I can bind this to a DataGrid, with a line

<DataGridTextColumn Binding="{Binding Entry}"/>

This results in the DataGrid showing the entries, with the one at Table[0] appearing as the first line, the one at Table[1] appears as the second line, etc. All this just works.

The problem is that I would like to treat Table as a ring buffer, so that as old entries get overwritten. Doing it like this winds up with new entries usually getting created somewhere in the middle of the DataGrid. What I would like to do (if possible) is to use a value converter so that a DataGridTextColumn can pick up the Index part of the table, use that to calculate a newIndex which describes the part of the table which has the line I really want to show. I would like new entries to appear at the bottom of the datagrid, and have old entries slide off the top and disappear.  Perhaps by something like this:

<DataGridTextColumn Binding="{Binding Index, Converter={StaticResource something}}" />

I get error messages such as "The Property 'Converter' was not found in type 'Binding'" or "Cannot resolve property 'Converter' in data context of type 'string'. I tried changing the type of Index to int, I still couldn't get things to work.

Is there any reasonable way to get a DataGrid bound to a ring buffer? Should I use something else instead of a DataGridTextColumn? Is there any other reasonable way to create an infinitely-scrolling display that can't run out of memory?


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images

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