c# - How to get specific column from database and work with this data in a datagridview using Entity Framework? -
i have 8 tables in database. when choose 1 of them , show data in datagridview using entity framework, columns navigation properties. how can hide these columns?
for example, electrolyte
table code:
public partial class electrolyte { [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2214:donotcalloverridablemethodsinconstructors")] public electrolyte() { this.experiment = new hashset<experiment>(); } public short electrolyte_id { get; set; } public string electrolyte_name { get; set; } public string formula { get; set; } public nullable<int> component_content { get; set; } public nullable<double> thermal_conductivity { get; set; } [system.diagnostics.codeanalysis.suppressmessage("microsoft.usage", "ca2227:collectionpropertiesshouldbereadonly")] public virtual icollection<experiment> experiment { get; set; } }
i tried use code, can't add , delete data via datagridview:
var query = c in con.electrolyte select new { electrolyte_id = c.electrolyte_id, electrolyte_name = c.electrolyte_name, component_content = c.component_content, formula = c.formula, thermal_conductivity = c.thermal_conductivity }; bindingsource source = new bindingsource(); source.datasource = query.tolist(); tableview.datasource = source;
how view specific columns , work database via datagridview @ same time?
you can hide them:
tableview.columns["electrolyte"].visible = tableview.columns["user"].visible = tableview.columns["machine"].visible = tableview.columns["material"].visible = false;
Comments
Post a Comment