C# WinForms - Manually Added Datagridview using Serialized JSON Object doesn't display data -
i've reviewed 100+ post , articles on , elsewhere , have yet figure out why example below won't show columns or rows. there has got simple thing i'm doing out of order or plain wrong causing fail.
overall, goal able manually add data grid form after drag , drop of json file winform. however, example below test code json serialized object , see if can display data in data grid. i'm using c# winforms in 2015.
so far no luck. missing?
serialized object using system; using system.runtime.serialization;
[datacontract] public class connections { [datamember(name = "id", isrequired = false)] public int id; [datamember(name = "name", isrequired = false)] public string name; }
form
public partial class form1 : form { datagridview datagrid = new datagridview(); public form1() { initializecomponent(); datacontractjsonserializer js = new datacontractjsonserializer(typeof(connections)); string testdata = "{ \"id\": 1, \"name\": \"testsetting\"}"; memorystream ms = new memorystream(encoding.utf8.getbytes(testdata)); connections connection = (connections)js.readobject(ms); ms.close(); bindingsource binder = new bindingsource(); binder.datasource = typeof(connections); binder.add(connection); binder.add(connection); binder.add(connection); datagridview datagrid = new datagridview(); datagrid.datasource = binder; datagrid.autogeneratecolumns = true; datagrid.autosize = true; this.controls.add(datagrid); }
Comments
Post a Comment