We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

to have an unbound column

Hi, I''m trying to create a table for a grouping grid just to support an unbound column. The code below works if i don''t try to set the type of the columns (all string). the original dataset does work fine too. i tried break on exception but doesn''t break, i guess its outside... this.ds1 = new DataSet(); DataTable t = new DataTable("workorders"); . . . int c = this.dataSet691.Tables[0].Columns.Count; for (int i = 1; i < c; i++) { if (i == 3) t.Columns.Add("Distance", System.Type.GetType("System.Double")); t.Columns.Add(this.dataSet691.Tables[0].Columns[i].ColumnName, this.dataSet691.Tables[0].Columns[i].GetType()); } foreach (DataRow dr in this.dataSet691.Tables[0].Rows) { DataRow r = t.NewRow(); foreach (DataColumn dc in dr.Table.Columns) { if (dc.ColumnName != "seq") r[dc.ColumnName] = dr[dc.ColumnName]; else r["Distance"] = pus[dr["seq"].ToString().Trim()]; } t.Rows.Add(r); } this.ds1.Tables.Add(t); this.dataSet691.Dispose(); this.gridGroupingControl1.DataMember = ""; this.gridGroupingControl1.DataSource = this.ds1.Tables[0]; I get endless exceptions of this type after the _Load function: System.Reflection.TargetInvocationException: Property accessor ''Caption'' on object ''System.String'' threw the following exception:''Object does not match target type.'' ---> System.Reflection.TargetException: Object does not match target type. at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Reflection.MethodInfo.Invoke(Object obj, Object[] parameters) at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) --- End of inner exception stack trace --- at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) at Syncfusion.Grouping.FieldDescriptor._GetValue(Record record) System.Reflection.TargetInvocationException: Property accessor ''AllowDBNull'' on object ''System.String'' threw the following exception:''Object does not match target type.'' ---> System.Reflection.TargetException: Object does not match target type. at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Reflection.MethodInfo.Invoke(Object obj, Object[] parameters) at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) --- End of inner exception stack trace --- at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) at Syncfusion.Grouping.FieldDescriptor._GetValue(Record record) Can you spot some reason for this? missing something? thanks

4 Replies

AD Administrator Syncfusion Team July 9, 2005 06:38 AM

Are you trying to swap out "seq" with "Distance"? Because of this code, int c = this.dataSet691.Tables[0].Columns.Count; for (int i = 1; i < c; i++) { if (i == 3) t.Columns.Add("Distance", System.Type.GetType("System.Double")); t.Columns.Add(this.dataSet691.Tables[0].Columns[i].ColumnName, this.dataSet691.Tables[0].Columns[i].GetType()); } both seq and distance are being added to the new datatable. Because of this code, foreach (DataColumn dc in dr.Table.Columns) { if (dc.ColumnName != "seq") r[dc.ColumnName] = dr[dc.ColumnName]; else r["Distance"] = pus[dr["seq"].ToString().Trim()]; } Distance gets populated twice (once for seq and once for distance), and seq never gets populated. This means there is a column of nulls in your new table for seq and maybe this is causing the problem. You could also try to do this using this.gridGroupingControl1.TableDescriptor.UnboundFields.Add (this.gridGroupingControl1.QueryValue) to add an unbound field to the grid using the old datatable as a datasource without duplicating the old datatable.


AD Administrator Syncfusion Team July 9, 2005 08:28 AM

Hi Clay, i don''t see what you mean cause there''s "for (int i = 1; ..." and seq is in 0. and in foreach (DataColumn dc in dr.Table.Columns) there is no Distance there since it is the table from the original dataset, right? so i think it should work, what''s the problem with setting types? can you show me some code to get unboudfields working for this case? pus holds the distances with seq as the key... dont want to show seq to the user though. thanks alot!


AD Administrator Syncfusion Team July 9, 2005 08:37 AM

just found the problem: t.Columns.Add(this.dataSet691.Tables[0].Columns[i].ColumnName, this.dataSet691.Tables[0].Columns[i].GetType()); should be t.Columns.Add(this.dataSet691.Tables[0].Columns[i].ColumnName, this.dataSet691.Tables[0].Columns[i].DataType); now it works fine. but if you have time to show me the unboundfields thing i''ll probably use it.


AD Administrator Syncfusion Team July 9, 2005 11:27 AM

You add an unbound column using the TableDescriptor.UnboundFields.Add method. Then in the QueryValue event for your unbound field, you can provide whatever value you want for the cell. Take a look at this sample. It shows how to add a unbound field. Syncfusion\Essential Suite\3.0.1.0\Windows\Grid.Windows\Samples\Grouping\EmployeeTerritoryOrder Once you have added an unbound column, you can use it like any other column. In particular, you can set any of its style properties using the columns Appearance object. this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("boolCol"); this.gridGroupingControl1.TableDescriptor.Columns["boolCol"].Appearance.AnyRecordFieldCell.BackColor = Color.Red; //used to provide values for teh unbound column this.gridGroupingControl1.QueryValue += new FieldValueEventHandler(gridGroupingControl1_QueryValue);

Loader.
Live Chat Icon For mobile
Up arrow icon