Need help creating a control to display data

I am writing a .NET WinForms application that should display a list of results in a user friendly format. This is how I hope to display the data.

alt text http://img398.imageshack.us/img398/4336/imgdyu.png

The table should support a decent amount of data (> = 200 separate "data blocks") and should be fast enough. I do not know how to do this, and I was hoping for some direction and advice. I created a quick prototype of a user control that just used a bunch of text fields stacked on top of each other. It worked reasonably well, but Windows is tackling text fields too quickly. I could create a custom text box control, but that would take a lot of time, and I was wondering if there are any recommendations for alternative solutions? Thanks.

+4
source share
8 answers

You can use a third-party control for this (maybe), but here are a few reasons why this is a potentially bad idea:

  • third-party controls spend money
  • third-party controls tend to suck
  • third-party controls require you to distribute at least an additional DLL that you usually don't have control over
  • even if a third-party control can ultimately do what you need, it will take you some time and effort to figure out how to use it and how to drive it into the form you need.

For something unusual (like what you are doing), writing your own UserControl is the best way for these reasons (among others):

  • Writing your own UserControl is the most interesting thing you can do in .Net
  • you need to learn some things to do it well, but the knowledge gained is immediately transferred to other problems and projects (whereas everything you learn about using Initrode Infinite Wonderfulness Gridifier will only help you in using this particular control)
  • there will be nothing extra to distribute with your application
  • complete source control
  • free forever (with an apology to Avoni)
  • the sky is the limit - with any third-party control, you will end up with something that it simply cannot do, but if you do it yourself, you can literally do whatever you want.

Your specific problem (well described in your question, thanks to the graphics) is quite easy to do, as a mostly user-defined UserControl (with a TextBox or two thrown in the mix). The only methods you will need from the System.Drawing.Graphics object are DrawRectangle, FillRectangle, MeasureString and DrawString. You don’t even need documentation, as Intellisense will provide you with everything you need.

If you have any problems, I will write you this for cookies with a chocolate chip. :)

Update : since you need the text to be selectable, this makes this approach more complicated. Implementing your own functionality like Textbox is a huge pain in firecrackers, but a relatively simple solution is to add a real multi-line text block on top of any text rectangle when the user clicks on it, and place the rectangle text (previously selected) in the text box. When this temporary text field loses focus (LostFocus), you draw the edited text into a rectangle and delete the text field. This way, you only have one text block at a time in your UserControl.

This version will cost you two cookies.

Update 2 . Below is a simple application that shows how to use one text block to create the whole control is selected and edited. And here is the source code .

+3
source

You can use the WinForm network control to achieve this or any third party component or list.

In a WPF ListBox with a data template, you can also achieve similar behavior.

0
source

Will the DataRepeater from Visual Basic PowerPack work for you? This is a download for VS2k5 and an installation with VS2k8. If not, check out TemplateListBox at www.codeproject.com/KB/cpp/TemplateListBox.aspx and ContinousControl at blogs.vbcity.com/hotdog/archive/2006/10/26.aspx.

0
source

Without knowing more about data types, I think you want the user control to be "repeated." You can use the TableLayout control (or FlowLayout, maybe?) And add / remove items from the table as needed.

If your data is tabular, perhaps with a relationship between parents and children, I would say that you should use a grid control. I do not agree with the statement of the other answer here that you should avoid third-party control. They will save you time very quickly - some, for example, Janus’s GridEx control, cost relatively little (a few hundred pounds) and save you hours that, if you work in a commercial environment, can translate much more than the cost of control. In addition, they look much better and offer better functionality than the standard WinForms network control.

0
source

I don't know the nature of the zero point you want to display, but for quick execution, System.Windows.Forms.DataGridView does this job well and is built into the .NET Framework 2.0.

If you are used to working with Linq to SQL Classes, if you use SQL Server as a data warehouse, just create your DBML diagram and:

  • Add data source;
  • In the window of the data source tool, select the display in the form of a grid and drag it into your form;
  • Edit the columns and change their order as you want them to appear for your client;
  • In the code, set DataGridView.DataSource = someObject.GetList (), which will return the IList of the object you want to display in this grid.

It only takes ten lines of code and a couple of Windows Forms development times. I hope I have not forgotten anything important. :-P

Please let me know if this helps!

0
source

You may want to publish the EditingControl property for your object if you wrote it yourself and create a new instance for each instance of your class retrieved from the database.

 someObject.GetList().ForEach((so) => { ConstructorInfo ctor = so.EditingControl.GetType().GetConstructor(new Type[] { }); var editingControl = ctor.Invoke(new object[] { }); editingControl.Name = "someName" + ++counter.ToString(); editingControl.Location = new Point(posX, posY); editingControl.Width = someWidth; editingControl.Height = someHeight; editingControl.DataSource = so; myForm.Controls.Add(editingControl); }); 

Well, hope you can get this idea. This is not very optimal as a solution, but, in any case, not bad, from my humble point of view.

Hope this helps!

0
source

For me, this seems like a great exercise in controls that are painted themselves. Instead of creating text fields, redefining / subscribing to the OnPaint event and using the Graphics object in DrawString () in the appropriate places, DrawRectange () has rectangles around them. If you know the position for your text fields, existing code will be quite easy to convert.

Some tips:

  • for the first version: don’t worry, limiting the drawing to the visible part of the control (I think you will need to scroll here)
  • for (1) - the graphics will do the cropping for you, and you can take care of it manually as soon as you confirm that you have the correct layout and the right data on the screen.
  • use double buffering to reduce flicker in all ways.
  • use sunscreen

Feel free to comment on further questions ...

0
source

If this is a web application:

Is this data editable on the page or is it for display only? If the first one, think of each element as a link to a new editor page that will edit one block at a time.

If you only show data that cannot be edited, use the repeater control to display the HTML table. Take a look at

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/repeater.aspx

The repeater communicates with any data source - List <>, Array, DataTable, etc. - and iterates through the content and displays the data for each row according to the pattern specified in aspx.

If this is a winForms application

Ask yourself why your application is not based on the Internet. Currently (in my very humble opinion) there are very few applications that are better suited to implement winForms. Good examples are graphic editors, compilers, etc. However, the reporting engine is likely to be better suited for web implementation. YMMV.

If you are still using WinForms, a better solution would be to use a label or other, handleless control for your text. Link to another form if you need to edit each entry. Any page with thousands of text fields will provide limited usability.

-2
source

All Articles