Hi,
I am using WPF controls version 12.2 XamDataGrid in my application. I am trying to create some Unbound columns during GridInitialize method. I am also a view model which returns me the data into a data table that I use to bind the columns in XamDataGrid.
The issue I am running into is the columns are dynamic and it gets the label from database which happens to have comma in the field name/label. Here is how I am setting the properties of unbound field.
public static UnboundField GetUnboundField(string name, string label, bool isVisible, bool isAllowEdit)
{
var field = new UnboundField()
Name = name,
Label = label,
Visibility = isVisible ==true ? Visibility.Visible : Visibility.Collapsed,
BindingPath =new PropertyPath(string.Format("Data[{0}]", name)),
BindingMode =BindingMode.TwoWay,
Width =FieldLength.Auto,
};
field.Settings.AllowEdit = isAllowEdit;
return field;
}
As you notice, when I am passing the name which has a comma, the value is not being bound even though my data table has value.
For example: Column Name from data table = "CY Salary,Incentive and Award"
BindingPath is coming as Data[CY Salary,Incentive and Award] --> does not bind the value to grid. If I remove the comma, I see the value in xamDataGrid.
I tried few things such as using escape character, enclosing the label in square brackets etc., but no luck.
Any help would be appreciated.
Thanks in advance.
Parvez
Hello Parvez,
I am just checking if you require any further assistance on the matter.
Hi Parvez,
Thank you for your reply. I have been looking into your scenario and my suggestion is not to change the name of the fields(the name of the columns coming from your database). You could allow your user to change only the ‘Label’ text of the fields since it applies commas.
Let me know, if you need any further assistance on his matter.
Hi Yanko,
Thanks for looking into this issue and sharing some references. The column names are dynamically coming from a database based on meta data. Our business users have the ability to name the columns and we use the QUOTENAME to pull the columns as they may contain spaces and special characters including comma.
I don't have an issue at the database level from trying to pull the data thru a T-SQL or stored procedure. But the issue is coming when trying to bind this data to grid using Unbound columns.
Is there a way to handle this using escape characters or by enclosing them in square brackets etc.,?
If there is no easy way of handling this, then please let me know so that I can go back to business and share this comma cannot be included in the column name(meta data).
Regards
Parvez.
Thank you for your post. I have been looking into your issue and I am not sure why you are using commas in the names of the properties since this is out of all conventions provided in naming guidelines. For more information about the naming guidelines you could look into the following MSDN link:
https://msdn.microsoft.com/en-us/library/xzf533w0(v=vs.71).aspx
A possible issue like yours is discussed in the following thread about SQL database:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/85962f12-70a0-4a3f-bbfd-64d4f35914fe/issue-with-sql-server-name-containing-comma?forum=sqlnetfx
Let me know, if you need any further assistance on this matter.