Store and export data from C# application - c#

I'll try to explain this the best I can!
I've written a program that after some input, it brings 4 different text items into 4 separate ReadOnly text boxes. I'm looking to, when a user presses a button, it will store the strings from the 4 text boxes into a sort of table, so when the user then enters more data and it calculates a new set of 4 strings, when the press the button again, it will also store these values. The user should then be able to print this "table" style storage or export it into excel.

One approach could be -
You can create a class with properties to hold all the text boxes values. Something like this -
public class TextBoxesDetails
{
public string TextBox1Value { get; set; }
public string TextBox2Value { get; set; }
public string TextBox3Value { get; set; }
public string TextBoxValue4 { get; set; }
}
Next declare a global list variable of this type
List<TextBoxesDetails> TextBoxesDetails = new List<TextBoxesDetails>();
Now at the click of your button, store the values of all the text boxes into this list -
TextBoxesDetails.Add(new TextBoxesDetails {
TextBox1 = TextBox1Value.Text ,
TextBox2 = TextBox2Value.Text,
TextBox3 = TextBox3Value.Text,
TextBox4 = TextBox4Value.Text"
});
Now just use this list to export to excel.
For exporting to excel, I would suggest, https://npoi.codeplex.com/. The tool is also available through Nuget packages.

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.

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?

I can't get data from get set auto data property c#

I'm a Student struggling and working for our System, and the code I used can't the data needed
first form
public int transactionNo { get; set; }
public int processNo { get; set; }
and here's my code to get the data:
from a button click event
transactionNo = int.Parse(lblTRANSACTIONO.Text);
processNo = int.Parse(lblprocessNO.Text);
the lblTRANSACTIONO.Text and lblprocessNO has the right value,
and here's how I get the data to use it on labels of another form:
second form from the load event
FORMtransactionADD FtA = new FORMtransactionADD();//first form
lblTNo.Text = FtA.transactionNo.ToString();
lblPNo.Text = FtA.processNo.ToString();
here's the output:
dont mind the 2017000 because it is the default text of those labels
The code doesn't work, is there any other way of setting auto data and getting it?
You need to pass data in other forms constructor.

make a structure for generating custom form

I am developing a learning management system with asp.net c#
now i want to make a structure for generating university forms , but these forms may change in future or need new forms , i want make a structure for admin of website to generate custom forms without coding, admin only add the name of feilds and type of that ( its text box or checkbox and ... ) , then it should be a printable from , also admin can add explanation in diffrent part of the form...
i dont know how should i do this ?
is there any API or some idea ?
You could make some clases for your form controls like: InputBox, TextBox, CheckBox, RadioButton. Then a form class could contain lists of your input controls.
class FormInputControl
{
public string Description { get; set; } //Every form input has a description like User, link, what you want that form input control instance to describe
public abstract object Value { get; set; }
}
class InputBox : FormInputControl
{
public string Text { get; set; }
public overwrite object Value
{
get { return Text; }
set { Text = value as string; }
}
}
class Form
{
public IList<FormInputControls> { get; set; }
}

What control can display multicolumn data simply

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).

Categories