Text user control with sorting possibility - c#

I need control in winforms that can add tens lines per second. I use now richtextbox, but i'm looking for something with sorting possibility (according some datatime or int)
Lines which are added are just custom objects complex of several int and datetime.
Delay aspect is quite important here.
EDIT:
It can be also some table/grid, but I suppose it take too much time (searching existing lines and inserting new line into appropriate place)

RichTextBox will typically offer more overhead in managing, searching, and inserting.
Much more appropriate would be a control like ListView. It gives simpler control over sorting, scrolling, and more.
Additionally, ListView has the ability to handle Virtual data backing. If performance or content size is an issue, this will let you only worry about the sub-set currently displayed in the ListView "view" window.

Two options
Use RichTextBox as you are doing now hold the data in a structure like SortedList from which the control will be updated.
Or, you can use a Grid, format the look and feel of the grid to remove the row & column grid lines and each new line will get appended this way you can let user sort by clicking on the header...
As for adding say ten lines per second I am pretty certain both these controls can handle more traffic than that....

Related

Customize Data Grid View in Windows Form

Like this
how can I customize datagridview to be like this photo in like
which means its start with full empty rows, like in accounting programs
Firstly, I would not recommend that you do this. Most good accounting programs don't do it either!
That said, the first way to do it would be to create a suitable set of data with the required number of rows already in it and then assign that as the data source. If you go beyone the available list then add a new row to the datasource.
The second way to do it would be to subclass DataGridView and handle the drawing yourself to draw the grid to mimic the rows.
I cannot recommend either option, and would recommend simply allowing new rows to be automatically added as the user enters something in the 'new' row. This is the way that most good programs do it.

Always show filter cell editors in RadGridView - Telerik for WinForms

I am using a basic RadGridView to show some data in a WinForms application. I have set the RadGridView to EnableFiltering and that is working just peachy. I have also set the GridFilterCellElement to Collapse both the filter icon, and the filter cell text that says "Contains:", and "Equals:", etc. The filter cells essentially look like empty grey cells right now, until one of them gets focus... at which point in time the proper editor fills the cell. I am setting the visibility of the filter icon and the filter cell text in the ViewCellFormatting handler of the RadGridView.
What I want to know, is how can I just make the editors for the entire row of filter cells, just show by default? In other words, I just want to show the editors in the filter cells at all times so it is completely obvious that the user can filter the data with the editing controls above.
I thought this was going to be very easy, but it has proven to be quite tricky. Any help would be greatly appreciated.
I would suggest against showing the editors at all times, despite the fact it will not be a trivial task, there is a reason for the editors to work the way they do.
Editors basically consist of some controls in them - being text box, drop down list, date picker etc. Controls, as we know are not lightweight objects (having plenty of controls shown will have significant performance impact) and do have some limitations e.g. they don't support clipping.
As RadGridView uses virtualization for its cells, cell elements are being reused during operations like scrolling, filtering, etc. Cell elements are much more flexible and overcome the limitations that Controls introduce and also, they are lightweight elements, as opposed to controls, which provides great performance, hence the grid can display plenty of data.
I hope I managed to explain why I don’t think this is a good idea.
The elements - icon and text, that you have hidden, are there precisely to show the user that these are filter cells.
If you need faster input, you can perhaps open the editor automatically (using CurrentCellChanged and BEginEdit method) when the user clicks on it.

Using a custom UserControl as a Column in a DataGridView

I've created a custom User Control that inherits from UserControl. It is pretty basic, it has some text fields, drop downs, and some radio buttons for right now. Ultimately I would like to string together 100's of these side by side to allow the user to fill out as many as they would like. The ideal solution to this would be to have a DataGridView where each column is an instance of my custom User Control. Is there a way to accomplish this? Or perhaps a better/alternative solution?
My initial thought is I'll need to create a custom DataGridViewCell that uses this custom control, but I don't know if this is a) possible and b) the most efficient way to do this.
I'm working with winforms.
You want to use a UserControl as a Column in a DataGridView. To display scores/rows/columns of your UserControl ('yuc') there are several options. Here are three that come to my mind:
Drop the DGV and go for a FlowLayoutPanel. This is simple to implement and will work pretty much out of the box. The only con is that the performance will get sluggish if you have too many controls in total in it. Let's assume your UC (yuc) has 10 controls; a few thousand controls are the limit in WinForms, so a few (100-300) yucs will work ok, but beyond that you need to rethink the design.
Go all the way and create a specialized DataGridView Cell that will host your yuc. Here is a complete and nice walk-through. As you can see this will amount to quite a lot of extra work; classes to add, interfaces to implement etc.. And, what is worse: All this is really meant to make the new cell type act like a regular DGV cell, read it will hold and allow you to edit only one value. That's a lot less than what your yuc probably can do..
Option 3: Cheat! You can combine the avantages of yuc data and DGV display performance if you display only one yuc in the current cell by overlaying it and make all other cells display what their yucs would look like.
This third option will allow you to add pretty much as many rows as your memory allows, although it is worth mentioning that the total column widths can't exceed 64k.
I can think of two ways to create the right display: The cells could display a Bitmap they hold along with their other data in a Tag structure or they could paint them in the CellPaint event. The former takes more memory but should work faster.
You need to create a data class yucData for your yuc that holds all data needed to initalze a yuc. It could also hold a Bitmap a yuc can create using the DrawToBitmap method.
Now each time the current cell is moved you show/move the editing yuc and initialize it to the data in the cell's Tag. When the values have changed you update the Bitmap.
And in the CellPainting event you draw the Bitmap into each cell.
See here for an example of overlaying a UserControl onto a DataGridView. There it overlays a whole row, which grows accordion-like to hold all its size.. The other rows and cells are quite regular..
What I wrote is about rows but you can just as well put them into columns you create dynamically.
But all this is really only worth it if you hit the limit of controls in Winforms with a FLP.
Well, if WPF is an option, there all this will not be an issue..
Excuse me.I can not write English.
But the sample code I wrote may help solve this problem and I am happy if that happens.
Display user controls in C # 4.0 Winforms DataGridView

massive string array (40000) elements in listbox

I know this is a stupid question, I need to let you guys know that I am fully aware that it is useless in 99% of situations to make a listbox with this many elements in c#:
That being said I need this to be done...is there any way to populate a listbox with 40000 elements without it completely destroying performance/freezing up, thanks!
note: I have tried it, this is per the exact requirements of a professor...when adding 40000 elements through a DataSource and DataBind the application freezes up
You tell me.
for(i=0;i<40000;i++)
{
listBox1.Items.Add("click me");
}
Even if is possible (I never tried it), the usability for this form will be 0.
In that cases a more usable implementation is via lookup text-boxes and lists, where the user can enter a text to search record that matches this text and displays them in a any kind of list.
It is of course possible to do it, but not very practicable.
When using a desktop technology like WinForms or WPF, for a large number of items like this you are better off using something like an auto complete textbox, and have it set to filter/search after the user has typed two or three characters. In this case you can also use a control that offers scrolling virtualisation - this means that there is only a limited number of UI elements created in the scrolling portion of the dropdown, and those elements get reused when a scroll occurs. If you don't use virtualisation then a new element gets created for every list item that gets scrolled in to view. (Note that Silverlight controls have this functionality - just in case it's an option).
For ASP.NET though I would suggest that you do not want to do anything that would cause a large transfer of data (large items, or small items but lots of them) as it won't be performant. Instead you should look to do what Google does - retrieve search results in a paged fashion.

WPF (irc) chat log control

I'm trying to learn WPF and was thinking about creating a simple IRC client. The most complicated part is to create the chat log. I want it to look more or less like the one in mIRC:
or irssi:
The important parts are that the text should be selectable, lines should wrap and it should be able to handle quite large logs.
The alternatives that I can come up with are:
StackPanel inside a ScrollViewer where each line is a row
ListView, since that seems more suitable for dynamic content/data binding.
Create an own control that does the rendering on its own.
Is there any WPF guru out there that has some ideas on which direction to take and where to start?
I suggest you start with a good object model independent of the UI, and then try a multi-line TextBox or a RichTextBox.
Whether these will suffice will depend on exactly how long you want the log to be able to get. If you run into performance issues, you may need to look at virtualization.
First of all, you should consider if you want to select only entire row (like in a listbox), or if you want to select certain characters from a row (like in a textbox).
In the first case, I think a ListView or even a ListBox should be enough, both of them support virtualization when bound to collection and there should be no problem with huge amounts of data. A stack panel inside a ScrollViewer is a little bit like reinventing the wheel for this case and creating a new control is not a very inspired approach in my opinion (as the functionality you want can be achieved with the existing controls, in WPF).
In the second case, if you want to select some text inside of a line, or if you want word wrapping for your longest lines in the log and want to select individual parts of the wrapped lines, then you need to use a control more oriented on displaying text. Kent already suggested a RichTextBox, I would add AvalonEdit control or even the WebBrowser control in which you directly modify its HTMLDocument.
I would suggest to use RichTextBox too, and store items in a log file or database, if you run into performance issues.
Another solution is to use the WPF WebBrowser control and modifiy its HTML content with:
webBrowser.NavigateToString("<HTML><H2><B>This page comes using String</B><P></P></H2></HTML>");
More information about using WebBrowser control

Categories