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.
Related
I have a WinForms application with only one DevExpress GridControl inside.
This GridControl uses two GridViews and one relationship in Master-detail mode.
As dataSource for gridControl I am using following class:
public class DashboardParameter
{
public string Name { get; set; }
public int DataType { get; set; }
public int ValueType { get; set; }
public BindingList<DashboardParameterValue> Detail { get; set; }
public DashboardParameter()
{
Detail = new BindingList<DashboardParameterValue>();
}
}
public class DashboardParameterValue
{
public string Value { get; set; }
}
Here is the code for data loading:
private void MasterDetail_Load(object sender, EventArgs e)
{
data = new BindingList<DashboardParameter>();
var p1 = new DashboardParameter() { Name = "First", DataType = 1, ValueType = 1};
p1.Detail.Add(new DashboardParameterValue() { Value = "Value1" });
p1.Detail.Add(new DashboardParameterValue() { Value = "Value2" });
var p2 = new DashboardParameter() { Name = "Second", DataType = 1, ValueType = 1 };
p2.Detail.Add(new DashboardParameterValue() { Value = "Value3" });
p2.Detail.Add(new DashboardParameterValue() { Value = "Value4" });
data.Add(p1);
data.Add(p2);
gridControl.DataSource = data;
}
As I understand it, in this way my gridControl automatically finds master-detail relation and creating Columns for each field in class for DataSource (If AutoPopulateColumns property is true).
Trouble: I can not change ANYTHING in my detailView Columns. I dont know in wich time my dataView columns are being created. All of detailView properties are ignored.
For example, if i changing detailView.AutoPopulateColumn = false, Columns still are being created.
If I create custom GridColumn gridColumn1 and add there detailView.Columns.Add(gridColumn1), it will be ignored.
Only one thing i can do is using [DisplayAttribute] for changing DisplayName, Visible and so on.
Question: How must I change my code to be able to change my detailView.
For example, can I add Column in detailView after all auto-generated columns, or change Column type to ComboBox (using RepositoryItemComboBox).
You can customize a detail view in the GridView.MasterRowExpanded event handler. This event is raised when a master row is expanded and a corresponding detail view is created and configured. To access this view, use the GridView.GetDetailView method. Alternatively, you can handle the GridControl.ViewRegistered event.
One more solution is to create a pattern detail view and customize it at runtime or design time.
I suggest you to go through documentation for Working with Master-Detail Relationships in Code and Master-Detail Relationships.
You can create your views either based on your database structure or pragmatically by adding views and columns with their settings.
You can customize a detail view in the GridView.MasterRowExpanded event handler. Fires immediately after a particular detail clone has become visible. The MasterRowExpanded event fires when expanding a master row or when switching between details.
Example:
//Assign a CardView to the relationship
CardView cardView1 = new CardView(gridControl1);
gridControl1.LevelTree.Nodes.Add("CategoriesProducts", cardView1);
//Specify text to be displayed within detail tabs.
cardView1.ViewCaption = "Category Products";
//Hide the CategoryID column for the master View
gridView1.Columns["CategoryID"].VisibleIndex = -1;
//Present data in the Picture column as Images
RepositoryItemPictureEdit riPictureEdit = gridControl1.RepositoryItems.Add("PictureEdit") as RepositoryItemPictureEdit;
gridView1.Columns["Picture"].ColumnEdit = riPictureEdit;
//Stretch images within cells.
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.
I am developing a win form application and i am stuck in a situation with data grid view.
what i exactly want to do is, if i enter some bar code then according to the bar-code i want to get data and fill them in the the combo box of brand name and Item name and mrp and all.
Which event should i work on and how can i get data and fill in this data grid-view row.
You can do this in many ways, my experience with DataGridView I do as follows.
Suppose you have a model class for your dataGridView
public class MyBarcodeRow
{
private String barcode = String.Empty;
public String Barcode
{
get { return barcode; }
set {
barcode = value;
////TODO OPERATION ON OTHER FIELD
//FOR EXAMPLE GET DATA OF QUANTITY FROM DATABASE
this.Quantity = new Random().Next(Int32.MaxValue);
}
}
private int quantity = 0;
public int Quantity
{
get { return quantity; }
set { quantity = value; }
}
//AND OTHER FIELD
}
In your form drag a BindingSource and associated it
BindingSource.DataSource = MyBarcodeRow
Now when you insert the barcode and leave cells you can load other data values.
From experience I suggest you focus on the events of the BindingSource and the Get / Set methods of the class of model that uses the VIEW.
Then there are also many interesting events in the grid, however, these structures work best when used from this point of view
Use DataGridViewComboBoxColumn.DataSource.
For example you have a class of Brand
public class Brand
{
public int32 ID {get; set;}
public string Name {get; set;}
}
In the form create a list of Brands and fill it with data(from database I assume)
List<Brand> _brands;
this.dgvBrandNamesColumn.DataSource = _brands;
this.dgvBrandNamesColumn.DisplayMemeber = "Name";
this.dgvBrandNamesColumn.ValueMemeber = "Name";
After adding data to DataGridView
DataGridViewComboBoxColumn will select matched brand name from DataSource(_brands)
For more specific help, show code how fill datagridview with data and how/from where you get all brands names
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; }
}
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).