I want my custom PropertyGrid with student1 and student2 as nodes with "Name,Section,Percentage,School" as childs for both nodes.
I tried like this :
class StudentClass
{
private string name;
private string section;
private string percentage;
private string school;
[CategoryAttribute("Student1")]
public string School
{
get { return school; }
set { school = value; }
}
[CategoryAttribute("Student1")]
public string Percentage
{
get { return percentage; }
set { percentage = value; }
}
[CategoryAttribute("Student1")]
public string Section
{
get { return section; }
set { section = value; }
}
[CategoryAttribute("Student1")]
public string Name
{
get { return name; }
set { name = value; }
}
private string name1;
[CategoryAttribute("Student2")]
public string Name1
{
get { return name1; }
set { name1 = value; }
}
private string section1;
[CategoryAttribute("Student2")]
public string Section1
{
get { return section1; }
set { section1 = value; }
}
private string percentage1;
[CategoryAttribute("Student2")]
public string Percentage1
{
get { return percentage1; }
set { percentage1 = value; }
}
private string school1;
[CategoryAttribute("Student2")]
public string School1
{
get { return school1; }
set { school1 = value; }
}
}
public Form1()
{
InitializeComponent();
StudentClass sc = new StudentClass();
propertyGrid1.SelectedObject = sc1;
}
The Output is as shown below :
Now in the above picture for Student2 instead of "Name1,Section1,Percentage1,School1" I want to display same as student1.
But I didn't get the required output. So Kindly help me out of this.
I am using C# Winforms in VS2010
And Suggest me how to deny columns resizing i.e., I should not allow user to resize the columns.
You can use the DisplayName attribute:
private string name1;
[CategoryAttribute("Student2"), DisplayName("Name")]
public string Name1
{
get { return name1; }
set { name1 = value; }
}
But note that if the user puts the property grid into A-Z mode, they'll both end up next to each other with no real way to tell them apart. You may find there's a more appropriate way to represent your data.
Related
I am trying to create a class that contains a header for my list-box. I have two classes that I will be inserting in the listbox. The first class runs fine, but the second one I am making so that the array is entirely of strings is telling me that a method must have a value return type. What does this mean exactly? The error at hand is "HeaderItems."
namespace RETAILITEMSBLAKE
{
class HeaderClass
{
string HeaderDescription;
string HeaderPrice;
string HeaderUnitsonHand;
public HeaderItems(string HeaderDescription, string HeaderUnitsonHand, string HeaderPrice)
{
this.HeaderDescription = HeaderDescription;
this.HeaderUnitsonHand = HeaderUnitsonHand;
this.HeaderPrice = HeaderPrice;
}
public string HeaderDescriptions
{
get
{
return HeaderDescription;
}
set
{
HeaderDescription = value;
}
}
public string HeaderUnits
{
get
{
return HeaderUnitsonHand;
}
set
{
HeaderUnitsonHand = value;
}
}
public string HeaderPrices
{
get
{
return HeaderPrice;
}
set
{
HeaderPrice = value;
}
}
}
Here is my first class that is working correctly:
namespace RETAILitemsBLAKE
{
class ItemizedClass
{
string description;
int unitsonhand;
double price;
public ItemizedClass(string description,int unitsonhand,double price)
{
this.description = description;
this.unitsonhand = unitsonhand;
this.price = price;
}
public string Description
{
get
{
return description;
}
set
{
description = value;
}
}
public double Price
{
get
{
return price;
}
set
{
price = value;
}
}
public int Quantity
{
get
{
return unitsonhand;
}
set
{
unitsonhand = value;
}
}
}
}
So, my goal is to have the HeaderClass so that I can place them as headers in my Listbox. Is there an alternate way to do such? I want to place it on top of the code here:
namespace RETAILitemsBLAKE
{
public partial class FrmItemList : Form
{
ItemizedClass[] items;
public FrmItemList()
{
InitializeComponent();
ItemizedArray();
}
private void ItemizedArray()
{
ItemizedClass jackets = new ItemizedClass("Jackets", 12, 59.95);
ItemizedClass jeans = new ItemizedClass("Jeans", 40, 34.95);
ItemizedClass shirts = new ItemizedClass("Shirts", 20, 24.95);
items = new ItemizedClass[] { jackets, jeans, shirts };
foreach (ItemizedClass RetailData in items)
{
lstRetailitems.Items.Add(RetailData.Description + "\t\t" + RetailData.Quantity + "\t" + "$" + RetailData.Price);
}
}
}
}
Would anyone be of assistance? Thank you!
You are using construct method which needs as same as class name and it didn't need to set return data type, so the method name needs to write HeaderClass in HeaderClass class otherwise it needs to set return data type to be a normal method.
class HeaderClass
{
string HeaderDescription;
string HeaderPrice;
string HeaderUnitsonHand;
public HeaderClass(string HeaderDescription, string HeaderUnitsonHand, string HeaderPrice)
In the code below I hope that I specify correctly whats wrong. I need to be able to call item.departments.dept_Type and that should be possible because of the association that I have made. I don't need to create inner joins on a query to get the data if I understand correctly.
This is my PersonClass
namespace DATALAYER.DataHandler
{
[Table(Name = "People")]
public class Person
{
private int _DepartmentID;
public EntityRef<Department> _Department;
public Person() { this._Department = new EntityRef<Department>(); }
private int _ID;
[Column(IsPrimaryKey =true, Storage ="_ID")]
public int ID
{
get { return this._ID; }
set { this._ID = value; }
}
private string _p_FirstName;
[Column(Storage = "_p_FirstName")]
public string p_FirstName
{
get { return this._p_FirstName; }
set { this._p_FirstName = value; }
}
private string _LastName;
[Column(Storage = "_LastName")]
public string p_LastName
{
get { return this._LastName; }
set { this._LastName = value; }
}
private string _EmailAddress;
[Column(Storage = "_EmailAddress")]
public string p_EmailAddress
{
get { return this._EmailAddress; }
set { this._EmailAddress = value; }
}
private string _Password;
[Column(Storage = "_Password")]
public string p_Password
{
get { return this._Password; }
set { this._Password = value; }
}
private string _SSID;
[Column(Storage = "_SSID")]
public string p_SSID
{
get { return this._SSID; }
set { this._SSID = value; }
}
private string _DOB;
[Column(Storage = "_DOB")]
public string p_DOB
{
get { return this._DOB; }
set { this._DOB = value; }
}
private string _CellNumber;
[Column(Storage = "_CellNumber")]
public string p_CellNumber
{
get { return this._CellNumber; }
set { this._CellNumber = value; }
}
[Column(Storage = "_DepartmentID", DbType = "Int")]
public int p_Department_dept_ID
{
get { return this._DepartmentID; }
set { this._DepartmentID = value; }
}
[Association(Storage = "_DepartmentID", ThisKey = "p_Department_dept_ID")]
public Department Department
{
get { return this._Department.Entity; }
set { this._Department.Entity = value; }
}
}
}
This is my Department code
namespace DATALAYER.DataHandler
{
[Table(Name = "Departments")]
public class Department
{
//private EntitySet<Person> _Person;
//public Department()
//{
// this._Person = new EntitySet<Person>();
//}
private int _DepartmentID;
[Column(IsPrimaryKey = true, Storage = "_DepartmentID")]
public int dept_ID
{
get { return this._DepartmentID; }
set { this._DepartmentID = value; }
}
private string _deptType;
[Column(Storage = "_deptType")]
public string dept_Type
{
get { return this._deptType; }
set { this._deptType = value; }
}
//[Association(Storage = "_Person", OtherKey = "ID")]
//public EntitySet<Person> Persons
//{
// get { return this._Person; }
// set { this._Person.Assign(value); }
//}
}
}
Now the problem I'm thinking is that there is a problem with datatypes between the primary key of the person and a foreign key the departments. But Since they are both int I don't see how that can be a problem.
If someone can just explain my problem to cleary if Im wrong or something or help me with a solution pls.
Added this class
namespace DATALAYER.DataHandler
{
public class SHSdb2 : DataContext
{
public Table<Person> People;
public Table<Department> Department;
//public Table<Address> Address;
public SHSdb2(string connection) : base(connection) { }
}
}
Person table
Department table
Without this code it works but then I can only call stuff inside the table
[Column(Storage = "_DepartmentID", DbType = "Int")]
public int p_Department_dept_ID
{
get { return this._DepartmentID; }
set { this._DepartmentID = value; }
}
[Association(Storage = "_DepartmentID", ThisKey = "p_Department_dept_ID")]
public Department Department
{
get { return this._Department.Entity; }
set { this._Department.Entity = value; }
}
Seems like I fixed it with this not sure if its a fix or I just lucky if someone can still maybe explain this to me it would be much appreciated.
var personQuery =
from per in db.People
where per.p_FirstName == "Christian"
select per.Department;
I'm thinking by specifying that it needs to get the data from department it would allow it in the foreach.
My project has two classes. The first class has information about continents and it contains also a list of objects of countries (another class).
I also declared a list of continents that contains all the continents.
I've succeeded in filling the list from a file, and succeeded to show them in a DataGridView in the same form. But the problem is that I didn't find a way to show them in a child form that contains a DataGridView.
So, how can I transfer the list of continents to the child form so that I can be able to show them in it?
I tried serialiization and deserialization, but it didn't work, I just see the name of members of continent class and nothing else.
Here are the two class and code of toolstrip that show the child form:
// first class of continent
namespace WindowsFormsApplication1
{
[Serializable]
class continent
{
//champs
private string nomc;
public string Nomc
{
get { return this.nomc; }
}
private string sup;//SUP
public string Superficie
{
get { return this.sup; }
set { this.sup = value; }
}
private string pop;//POP
public string Population
{
get { return this.pop; }
set { this.pop = value; }
}
private string dens;//DENS :
public string Densité
{
get { return this.dens; }
set { this.dens = value; }
}
private string nbp;//NBP : 54 :
public string nombre_de_Pays
{
get { return this.nbp; }
set { this.nbp = value; }
}
private string fus;//FUS )
public string Fuseaux_horaires
{
get { return this.fus; }
set { this.fus = value; }
}
private string pnb;//PNB
public string PNB_habitant
{
get { return this.pnb; }
set { this.pnb = value; }
}
//constructeur
public continent(string nom)
{
this.nomc = nom;
}
public continent()
{
// TODO: Complete member initialization
}
//list of countries of that continent
public List<country> listep = new List<country>();
}
// class of countries
namespace WindowsFormsApplication1
{
[Serializable]
class country
{
//champs
private string nom_p;
public string Nom_pays
{
get { return this.nom_p; }
set { this.nom_p = value; }
}
private string cap;//PCAP
public string Capitale
{
get { return this.cap; }
set { this.cap = value; }
}
private string sup;// PSUP
public string Superficie
{
get { return this.sup; }
set { this.sup = value; }
}
private string reg;// REG
public string Régime_politique
{
get { return this.reg; }
set { this.reg = value; }
}
private string dev;//PDEV nationale
public string Devise
{
get { return this.dev; }
set { this.dev = value; }
}
private string hym;// PHYM
public string Hymne
{
get { return this.hym; }
set { this.hym = value; }
}
private string lg;// PLG
public string Langue
{
get { return this.lg; }
set { this.lg = value; }
}
private string mo;// PMO
public string Monnaie
{
get { return this.mo; }
set { this.mo = value; }
}
private string de;
public string PDE
{
get { return this.de; }
set { this.de = value; }
}
//constructeur
public country (string nom)
{
this.nom_p = nom;
}
}
}
and the code in the form is
//liste of contnents
List<continent> listec = new List<continent>();
// i filled it from a file
//here the code of toolstrip that open the childform
private void listeContinentToolStripMenuItem_Click(object sender, EventArgs e)
{
listecont flc = new listecont();
flc.ShowDialog();
flc.MdiParent = this;
}
In your child form, add an overload to the Form constructor that takes a Form as an argument. Then when you create your child form, you can pass in an instance of your current (parent) form like, listecont flc = new listecont(this); where this is a reference of your parent form. Now your child form can make calls to parentForm.Textbox.Text = "blablabal" or what ever object you want to interact with.
Why not just add a constructor to the listecont class that takes a List<continent>? Then, the child form will have the data when it's constructed.
in your MDI child add a method:
public void SetContinentData(List<continent> list)
{
// add your DataSource to the grid
// f.e.:
dataGridView.DataSource = list;
}
and in your Toolstrip handler:
private void listeContinentToolStripMenuItem_Click(object sender, EventArgs e)
{
listecont flc = new listecont();
flc.SetContinentData(listec);
flc.ShowDialog();
flc.MdiParent = this;
}
I have a customer object class:
public class customerObject
{
private string _address1;
private string _address2;
private string _address3;
private string _category;
private string _country;
private string _county;
private string _custcode;
private string _fullname;
private string _int_rep_hou;
private string _int_rep_key;
private double _lat;
private double _lng;
private string _postcode;
private string _rep_code;
private string _telephone;
public customerObject()
{
}
public string Address1
{
get { return _address1; }
set { _address1 = value; }
}
public string Address2
{
get
{
return _address2;
}
set { _address2 = value; }
}
public string Address3 { get { return _address3; } set { _address3 = value; } }
public string Category
{
get { return _category; }
set { _category = value; }
}
public string Country { get { return _country; } set { _country = value; } }
public string County { get { return _county; } set { _county = value; } }
public string Custcode
{
get { return _custcode; }
set { _custcode = value; }
}
public string Fullname
{
get { return _fullname; }
set { _fullname = value; }
}
public string Int_rep_hou
{
get { return _int_rep_hou; }
set { _int_rep_hou = value; }
}
public string Int_rep_key
{
get { return _int_rep_key; }
set { _int_rep_key = value; }
}
public double Lat { get { return _lat; } set { _lat = value; } }
public double Lng { get { return _lng; } set { _lng = value; } }
public string Postcode { get { return _postcode; } set { _postcode = value; } }
public string Rep_code
{
get { return _rep_code; }
set { Rep_code = value; }
}
public string Telephone { get { return _telephone; } set { _telephone = value; }
}
}
I have a CustomCollections class
public class CustomerCollection
{
public List<customerObject> Customers { get; set; }
}
My method that loops through dt rows and converts to a customer object
public List<Valueobjects.CustomerCollection> dolist(DataTable temptablename)
{
//Create Collection Object
Valueobjects.CustomerCollection Collection = new Valueobjects.CustomerCollection();
foreach (DataRow row in temptablename.Rows)
{
//Create Customer Object
Valueobjects.customerObject Customer = new Valueobjects.customerObject();
//set values of customer object
Customer.Rep_code = "";
Customer.Int_rep_key = "";
Customer.Int_rep_hou = "";
Customer.Fullname = row["Fullname"].ToString().Trim();
Customer.Custcode = row["Custcode"].ToString().Trim();
Customer.Category = row["Category"].ToString().Trim();
Customer.Address1 = row["Address1"].ToString().Trim();
Customer.Address2 = row["Address2"].ToString().Trim();
Customer.Address3 = row["Address3"].ToString().Trim();
Customer.Postcode = row["Postcode"].ToString().Trim();
Customer.Country = row["Country"].ToString().Trim();
Customer.Telephone = row["Telephone"].ToString().Trim();
Customer.Lat = Convert.ToDouble(row["Lat"]);
Customer.Lng = Convert.ToDouble(row["Lng"]);
Customer.County = row["County"].ToString().Trim();
//add to the collection (list)
Collection.Customers.Add(Customer);
}
temptablename = null;
return Collection;
}
However when I create a new Customer object and a new CustomerCollection object I am getting an error when adding the customer to the collection list.
Error:
Error 32 Cannot implicitly convert type
'Classes.Valueobjects.CustomerCollection' to
'System.Collections.Generic.List'
Your method is returning a List<CustomerCollection>:
public List<Valueobjects.CustomerCollection> dolist(DataTable temptablename)
{
//...
}
But the code is trying to return a CustomerCollection:
return Collection;
Just as the error says, these two types are different.
If a CustomerCollection is already a collection of customers, then semantically what is a List<Valueobjects.CustomerCollection>? A collection of collections? It seems like you're over-pluralizing your objects :)
There are two approaches here. Either return a CustomerCollection from the method:
public CustomerCollection dolist(DataTable temptablename)
{
//...
}
Or use a List<Customer> if you want to use generic lists as your collection containers:
public List<Customer> dolist(DataTable temptablename)
{
//...
var Collection = new List<Customer>();
//...
Collection.Add(Customer);
//...
return Collection;
}
Side note: You may want to stick to C# conventions for variable naming. As you can see from the code highlighting here on Stack Overflow, your variable names can easily be mistaken for classes/types, which can cause confusion when supporting the code.
Return a CustomerCollection instead of a List<Valueobjects.CustomerCollection>:
public Valueobjects.CustomerCollection Dolist(DataTable temptablename)
{
// ...
Your object has a list, it is not a list.
MSDN: Inheritance
Here is the thing, I have a problem creating a new object using the remote mechanism "marshal by value".
Here is my class:
[Serializable]
internal class Empleado_MBV
{
public Empleado_MBV()
{
Id = 123456789;
Nombres = "NotEntry";
Apellidos = "NotEntry";
FechaNacimiento = DateTime.MinValue;
Direccion = "NotEntry";
Metapreferencias = "NotEntry";
}
private List<Multas> _multas;
internal List<Multas> Multas
{
get { return _multas; }
set { _multas = value; }
}
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _nombres;
public string Nombres
{
get { return _nombres; }
set { _nombres = value; }
}
private string _apellidos;
public string Apellidos
{
get { return _apellidos; }
set { _apellidos = value; }
}
private DateTime _FecNac;
public DateTime FechaNacimiento
{
get { return _FecNac; }
set { _FecNac = value; }
}
private string _direccion;
public string Direccion
{
get { return _direccion; }
set { _direccion = value; }
}
private string _metapreferencias;
public string Metapreferencias
{
get { return _metapreferencias; }
set { _metapreferencias = value; }
}
public string _AppDomainHost
{
get { return AppDomain.CurrentDomain.FriendlyName.ToString(); }
}
}
But when I try to create an object in another "appdomain", the property "_AppDomainHost" of "Empleado" does not show the "appdomain" I had created, but show the "appdomain" by default. Some ideas?
AppDomain ad1 = AppDomain.CreateDomain("NewAppDomain");
//Crear new object in my new AD.
Empleado_MBV mbv_emp = (Empleado_MBV)ad1.CreateInstanceFromAndUnwrap("DEMO_MBV_MBR.exe", "DEMO_MBV_MBR.Empleado_MBV");
Console.WriteLine(AppDomain.CurrentDomain.FriendlyName.ToString());
Console.WriteLine("MBV : {0}",mbv_emp._AppDomainHost.ToString());
Console.ReadLine();
Result:
DEMO_MBV_MBR.vshost.exe
MBV : DEMO_MBV_MBR.vshost.exe
The result that I want:
DEMO_MBV_MBR.vshost.exe
MBV : NewAppDomain
You need to store AppDomain in Empleado_MBV's constructor.
What you are doing right now is displaying current AppDomain using its Current static property. It will return the AppDomain where current code is being executed.
Example:
private string _appDomainHost;
public string _AppDomainHost
{
get { return _appDomainHost; }
}
and in constructor:
_appDomainHost = AppDomain.CurrentDomain.FriendlyName.ToString();