Binding C# Objects to ListView / control - c#

I have a class that returns a list of "Category" Objects. I'd like to display them along the left-hand side of the page in a listview (if that's the best way to do it, even).
The category objects have normal attributes. Title, User, NumberOfProjects. I'd like to display both the title and the number of projects in this list.
Not worried about editability right now as we might make that separate (i.e. not in-line in a list view edit mode).
What do you think is the best way to do this?
Thanks in advance for any help you can give! :)

First if the array of the objects is too big I'd recommend to use virtual mode of ListView.
Second, nice way to "convert" youur object to string is to override ToString method where you can represent info of your object.

One alternative is to bind your collection to a DataGridView and display that, which would save you having to load each item manually but looks tacky and like it was made in Access.
Personally, I'd use a list view as you've suggested. I find that although you have to load its items manually, its simple and looks by far the most professional.

I was just looking for the best way to use a ListView control, I suppose.
I was able to figure it out -- I wasn't using correctly and hadn't included a "contentPlaceholder" element.
After doing this, I was able to use <%#Eval("FieldName")%> to insert the object's properties into labels. It was already in list format, so the databind was a snap.
If code would benefit anyone else, I'll post it -- I just didn't feel like cutting out all the extra CSS. ;)
Thanks to everyone who tried to help with this!

Related

Create a scrollable list of items and their properties in Winforms

I have a class and a bunch of objects of that class; I would like to create a scrollable list displaying a list of these objects' properties. How could I go about this in windows forms?
I need to format it in a way that the user can add and take away from the list any time they would like.
To clarify, have a box that has 1 objects properties, the second thing in the list would have the other objects properties, etc.
I would like to do it in a visually pleasing way as well, not just text. Maybe have a box with all the things displayed in it.
I am using c#, if that helps.
PS: I am not asking you to do it for me, but for a way to go about doing it myself.
Thanks in advance to anybody who replies. If you need any more info I will gladly give it to you.

Change the auto-complete behaviour of a textbox

I have two doubts about the autocomplete feature of textboxes in C#.
First, I want to display the full list, not only the ones that start with the given text, and secondly I want to prevent the auto-complete of specific options (some are category titles).
I've been checking the textbox properties and there's nothing related to it, so probably the main question could be, Is there a way to modify / override the textbox events in order to handle the auto-complete actions? (I don't know if it applies to show the full list too)
I assume you're asking about a winforms textbox, as I dont think the WPF textbox supports autocomplete at all.
The base TextBox class will not support doing what you want, so you could in theory attempt to override all of the functionality in the TextBox class to do what you want, but the better idea would be to create a new custom control that inherits from TextBoxBase and implement the autocomplete behavior the way you want it.
I'm not sure about displaying the full list (perhaps a combobox or similar is more suited to this?) but you can definitely do something like this to swap which list of possible items can be displayed.
Another option, though one I like less, is to remove items you don't want to display at a given time from the collection dynamically, like this: textBox.AutoCompleteCustomSource.Remove("ACategoryTitle")
I could foresee that approach having many problems with trying to rebuild the list constantly. I would probably create a subclass of AutoCompleteStringCollection that wraps some LINQ code to nicely select the union of some lists and not others to display in the textbox.
I decided to build my own autocomplete tool with the help of a simple listbox and events, then I could achieve what I was expecting..
The CodingGorilla's answer probably leads to a better solution if you want something more decent, in my case for speed reasons I decided to do it that way but I'll mark his answer as the accepted in order to help other people who have the same doubt and they could consider that point..

Creating a SQL Server view designer like control

I am in need of a view like designer for Winforms, so really I just need to make a control, but I'm not sure what path to go down or whether or not it has already been done.
I need something like this:
How do you think I should go about it?
Do you think that this is done in some kind of canvas? Or is there actually something that does this? I only need one with two lists that I can use multiple times. Suggestions?
EDIT
Its not a query designer that I want, but simply the mapping of one key to another.
This one by Bernardo Castilho, the CTO of componentone:
http://www.codeproject.com/Articles/43171/A-Visual-SQL-Query-Designer

making listView acting like treeView in winforms

is there any way to make winforms listView showing data like treeView. i mean to make it verticaly oriented and to show columnHeaders one under another and not to put them in horizontal line?
thanx for assistance
Consider using this open-source ObjectListView.
It's a mature control that can show all sorts of lists, a tree-list and much much more (not my code - I'm just a happy user).
It take a few minutes to get used to the idea of using it, but once you got it - using it is a breeze.
Examples:
You can also consider using Better ListView. The usage is 99% same as the original .NET ListView, but it has many extras. For example, every item has a ChildItems property in which you can put further children.

How to approach data-binding a BindingList of Lists to a DataGridView in C#?

I'm writing a program that functions as an Excel-style dictionary. Basically, it allows the user to add rows, edit rows, search through them, and so on. I use it for storing and studying vocabulary for foreign languages.
I've gotten a version up and running that I'm quite happy with. It uses a BindingList as a data source for a DataGridView in order to track changes and record them back to the BindingList that I use to store all the vocabulary, and the list itself is made up of a custom class I named "Term", that has properties for "English Word", "Spanish Word", "Examples", ect. What it doesn't do is let the user customize the fields, and that's where my problem comes in. It's pretty much "hard-coded" in that even if I'm studying Spanish or French, the Term class is going to be using the property for "Kanji" from Japanese.
I want to be able to have the user type in what fields they want the dictionary to display and keep track of--basically, they should be able to rename and add/remove columns from the DataGridView. My first thought was to implement this as a List, which stores the names of the fields (and accordingly the number of them, by using the List's length). Then, I would have a Word class that has a List property, and each string in the list represents one of the fields. Then I create a BindingList of this Word class, which leaves me with a BindingList of Lists.
When I try to databind my List list to my DataGridView, the grid comes up empty--it apparently has no idea how I want the data to be displayed and I'm having great difficulty figuring out how to tell it to. I'm not even sure if my approach of having a List of Lists is a good way to implement customizable fields, but it's the best I could think of. In any event, can anyone recommend a way to approach this that lets me add the fields to the table, but also tracks changes and pastes them back to the original source? I need the grid to be used as an editing tool for the user to not only add new elements, but also change existing ones.
It's a personal project, but it's driving me a bit crazy. I was up until 5AM last night trying to figure it out and came up empty-handed. Thanks very much for reading!
I've read your post a couple of times. I'm not sure I understand completly. If I don't, please give some details and I'll try to help.
If I had to do a Excel-like DataGridView, I think I'd use an Array. I would create an array of, say, 256 by 256 and put it as DataSource. Then after the user edits, you read the whole DataGrid and rewrite if it differs from the array you originally had.
I think you might be interested in this class:
http://www.codeproject.com/KB/grid/DGVColumnSelector.aspx
It allows the user to dynamically display which columns are shown in the DataGridView

Categories