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.
Unfortunately, activation email could not send to your email. Please try again.

to have an unbound column

Thread ID:

Created:

Updated:

Platform:

Replies:

31555 Jul 9,2005 02:11 AM Jul 9,2005 12:27 PM Windows Forms 4
loading
Tags: Grouping
Administrator [Syncfusion]
Asked On July 9, 2005 02:11 AM

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

Administrator [Syncfusion]
Replied On July 9, 2005 07: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.

Administrator [Syncfusion]
Replied On July 9, 2005 09: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!

Administrator [Syncfusion]
Replied On July 9, 2005 09: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.

Administrator [Syncfusion]
Replied On July 9, 2005 12:27 PM

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);

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;