What control can display multicolumn data simply - c#

I want to display data in one control Vertically with a window form control in C#, such as:
Title: The Game
Name: Andrew Smith
Age: 44
ISBN: 123456123456
Costs: £39.99
I'm looking for a simple display with code to add and remove items..
I have a list of data which I want to display quite simply from a list which will be displayed as Title/Item as above, which won't need to be amended only viewed.
Is there a way to find out the dimensions of the text and create padding, or is there an automatically adjusting multiple column type control? Any thing with some code to stop me going mad regarding special list Views and grid type views.

You can use DataGridView. It is simple to use.

You mentioned List Views in your post, and I think that is the answer for you. Try a ListView control with View set to Details. Use the Designer to create a column for each field in your data, and then use listView1.Items.Add() to add each item. (There is a constructor for ListViewItem which takes an array of strings; the strings are the values for each column.)

Create a BookItem class which has properties shown below.
public string Title { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public int ISBN { get; set; }
public string Cost { get; set; }
Generate a lstBookItems item List<> type and add BookItem items. But first, you must create bookItemInstance and fill data one by one.
List<BookItem> lstBookItems = new List<BookItem>();
lstBookItems.Add(bookItemInstance);
After this point, if you using ASP.Net
Create a Asp:ListView or Asp:GridView using Toolbox and give data source and bind data on code behind PageLoad() method
grdBooks.DataSource = lstBookItems;
grdBooks.DataBind();
And now, you can change appearence this gridView as you wish at Design screen(ex: vertical).

Related

Export CSV - Kendo UI Grid with filters

There is out of the box support for exporting Kendo Grid data in Xlsx and Pdf formats, I'm looking for something similar for exporting in Csv format.
I have tried the server export described in: https://demos.telerik.com/aspnet-mvc/grid/server-export, which just sends the visible rows to the action; My unfiltered grid has over 250k entries. The output I'm looking for is the data in this table with the filters applied. I can get the data again in the same way the grid was populated and filter the data server-side, but how do we pass the selected filters to the action?
There appears to be a number of possible solutions, but I'm hoping to save time on going down a dead end. The documentation is often good with Kendo, but I'm struggling to find what I need with this one.
A possible solution is to get the filters applied on the Grid and send it to the server side and export the result as a expected format. To get the filter applied on the grid, you have to act over the dataSource.
var grid = $("#myGrid").data("kendoGrid");
var filter = grid.dataSource.filter();
Then, you have to send via jquery ajax, the filter.filters array to an action and bind it into a Type, maybe, something like this:
public class GridData
{
public GridFilter[] Filters { get; set; }
public string Logic { get; set; }
}
public class GridFilter
{
public string Operator { get; set; }
public string Field { get; set; }
public string Value { get; set; }
}
Then, get the data based on the GridData object and return provide the CSV information.

Should i have a class for my drop down list?

I'm using a drop down list and i have a class in my view model proppertis looked like this
[DisplayName("شماره تیم")]
public List<int ?> TeamId { get; set; }
but i changed it to so i can use DropDownList
[DisplayName("شماره تیم")]
public List<SelectListItem> TeamId { get; set; }
here you can find everything about my project
should i use different classes in my view model for each View?
If you're going to have a list of items, and each item contains a value and corresponding text to display, then sure, having a class to represent that makes perfect sense.
I'll only split one hair, and this may be a tiny split hair.
public List<SelectListItem> TeamId { get; set; }
The name of the class - SelectListItem - suggests that your view model is "telling" your view how to represent this data, using a select control. But the job of the view model is just to pass data, not to determine how it should be rendered. Perhaps the same data could also be rendered using radio buttons.
Like I said, that's some major hair-splitting. Other than that, using a class that way makes perfect sense. That can help you to create reusable partial views that render those classes as select elements or radio button groups.

C# Textbox: Bind object to suggestion list

I am currently working at a project where I need to manage cities and their zip codes. Therefore, I created the fallowing object:
class Place
{
Guid Id { get; set; }
string Name { get; set; }
int ZipCode { get; set; }
... further fields
}
and filled a List<Place> with a number of Place. Now I have a Textbox where I can enter the name of the city or its zip code. I both cases I would like to get a suggestion list which match with the entered input like this
Example: input = "1234" or "City"
12341 CityOne
12342 CityTwo
12343 CityThree
...
If I than choose an item from this suggestion list I would like to get the related Place as a return value. How can I implement this feature in C# with a WindowsFormsApplication?
What you've asked isn't a simple or single question. I think you can have a hidden ListBox below the TextBox where the user will enter text.
Now TextBox has an event called OnTextChanged. This event is fired every time there is a change in the text. This means that this event is fired overtime a user adds or deletes a character in the corresponding TextBox.
You can use this event to filter the list to display in your ListBox.
Something like this
//Imagine the TextBox ID as CityZipTextBox and ListBox ID as CityZipSuggestionsListBox
protected override void OnTextChanged(EventArgs e)
{
string txtCityZip = CityZipTextBox.Text;
List<Place> suggestedPlaces = filterCode;//Code to filter the full list using the TextBox content
CityZipSuggestionsListBox.DataSource = suggestedPlaces;
}
Does this help?

Data binding property in dev express grid designer not found

I have this class as you can see :
public class Document
{
public int Id { set; get; }
public string Number { set; get; }
public string Class { set; get; }
public string Discipline { set; get; }
public string Unit { set; get; }
public DateTime SubmitDateTime { set; get; }
}
It has a repository to get data from database ,in my form in UI in put a gridviewDevExpress so i pass my data using my repository to dev express gridview
private void frmDocument_Load(object sender, EventArgs e)
{
gridControlDocument.DataSource = _documentRepository.Get().ToList();
}
I want to bind my class to grid view,so i define my columns in gridview as you can see :
I want to bind my data base columns to grid view columns .I don't know where is the property ?
The result of my running is :
I have a record in database
There is a property on DevExpress gridview for columns that is called FieldName. So you can add database column name to FieldName.
You should either to create all the specific columns with the correctly assigned GridColumn.FieldName properties or do not create columns at all (in this case the GridControl will automatically populate columns itself).
For details, I suggest you use the following tutorial which describes the XtraGrid's design-time data binding specifics: Create and Manage Columns at Design Time.
Please, also read the following article that describes the data binding aspects related to columns: Creating Columns and Binding Them to Data Fields
Moreover, you can use the Data Source Configuration Wizard that allows you to choose the specific binding mode (direct, server-side, parallel or asynchronous) for various data sources (ADO, EF, SQL, Excel, WCF, XML, IEnumerable/IList and etc).

How do I dynamically add and remove line items from an ASP.NET MVC view?

I have a PurchaseOrder model:
public class PurchaseOrder
{
public string OrderNumber { get; set; }
public string Customer { get; set; }
public IList<LineItem> Lines { get; set; }
}
and a LineItem class:
public class LineItem
{
public string PartNumber { get; set; }
public int Quantity { get; set; }
}
What I want to do is on my view for the PurhcaseOrder Create action, I need a section for line items. The user should be able to add a new line, remove a line, then submit. One caveat is the PartNumber needs to be a dropdown list of valid parts.
What can I do to accomplish what I'm looking for?
http://knockoutjs.com/ is pretty good for this.
http://knockoutjs.com/examples/cartEditor.html shows an editor which can add/remove lines and contains drop down.
and there's an old-ish article that discusses using Knockoutjs with asp.net mvc - http://blog.stevensanderson.com/2010/07/12/editing-a-variable-length-list-knockout-style/
If you want to do everything without js, then make a new action/view for adding and editing a line item. For deleting, it is bad practice to have an actionlink delete the item, a GET should never alter data. So a good pattern is to have the delete link go to a confirm page. And from that page you POST to the delete action (or cancel and go back)
I would create this functionality with jQuery (on a client side)
Part Number 1345 - 124 items [Remove]
Part Number 1489 - 101 items [Remove]
[Select part namber /] [_ Quantity _] [Add]
Plus you could duplicate this functionality (exactly the same UI) with server-side code for the clients who have JS disabled. In order to do that you could store temprorary LineItems in TempData (on each post back, when user clicks Add Line Item).

Categories