error: Two-way binding requires Path or XPath - binding

my xaml code:
<DataGrid x:Name="pRCPROFDataGrid"
EnableRowVirtualization="True"
ItemsSource="{Binding}"
RowDetailsVisibilityMode="Visible"
CanUserAddRows="True"
FlowDirection="RightToLeft" RowEditEnding="pRCPROFDataGrid_RowEditEnding"/>
my code c#:
DataTable tbl = lib.GetDataFromTable("SELECT column_name, data_type, nullable FROM user_tab_columns WHERE table_name = '" + _table + "' order by column_id", "Usr");
DataTable sourceTable = new DataTable();
string[] _label = lib.GetDetailsTable(_table);
for (int element = 0; element <= tbl.Rows.Count - 1; element++)
{
DataGridBoundColumn _xtemp = null;
if (tbl.Rows[element][1].ToString() == "bit")
{
_xtemp = new DataGridCheckBoxColumn();
}
else
{
_xtemp = new DataGridTextColumn();
}
_xtemp.Header = _label[element];
_xtemp.Binding = new Binding(tbl.Rows[element][0].ToString());
_grid.Columns.Add(_xtemp);
if (element == 0)
_xtemp.Visibility = Visibility.Hidden;
if (element == 1)
_xtemp.Width = new DataGridLength(1, DataGridLengthUnitType.Star);
}
_grid.ItemsSource = sourceTable.DefaultView;
the result:
Additional information: Two-way binding requires Path or XPath.
System.InvalidOperationException was unhandled
Message: An unhandled exception of type 'System.InvalidOperationException' occurred in Unknown Module.
Additional information: Two-way binding requires Path or XPath.

Solved same problem by removing slash from column header (name).

Related

Rotativa - controllercontext is null

i work with ASP.NET MVC and i try to use rotativa for build a pdf by model.
The problem is that in this context i operate in a model (i can't move the code in controller), and i write a procedure into a controller for build pdf. Like this
MODEL:
ModelNIR modelloNIR = new ModelNIR();
modelloNIR.ufficio = Ufficio;
if (r != null)
{
modelloNIR.ruolo = r.Descrizione.ToUpper();
//pdfFormFields.SetField("RUOLO", r.Descrizione.ToUpper());
//pdfFormFields.SetField("RUOLO2", "RUOLO " + r.Descrizione.ToUpper());
}
if (atto.IdTipoParte == 1)
modelloNIR.convenuto = 1;
if (atto.IdTipoParte == 2)
modelloNIR.ricorrente = 1;
if (atto.IdTipoAtto == 1)
modelloNIR.citazione = 1;
if (atto.IdTipoAtto == 2)
modelloNIR.altro = 1;
if (atto.IdTipoAtto == 3)
modelloNIR.ricorso = 1;
if (Contributo != "")
Contributo = "Euro " + Contributo;
else
Contributo = "Esente";
modelloNIR.valoreCausa = "Euro " + valoreCausa;
modelloNIR.contributo = Contributo;
modelloNIR.oggetto = oggetto;
if (ControparteNew == "") ControparteNew = Controparte;
modelloNIR.promosso = Promossoda;
modelloNIR.contro = ControparteNew;
NotificheMezzoPecsController not = new NotificheMezzoPecsController();
// call controller action
MemoryStream nir = not.createPDFNIR(modelloNIR);
And this is the controller's action
CONTROLLER:
public MemoryStream createPDFNIR(ModelNIR modelloNIR)
{
var actionPDF = new ViewAsPdf("NIR", modelloNIR) //some route values)
{
FileName = "NotaIscrizioneRuolo.pdf"
//CustomSwitches = custom,
//PageSize = 4
};
byte[] applicationPDFData = null;
try
{
applicationPDFData = actionPDF.BuildPdf(ControllerContext);
}
catch (Exception ex)
{
throw;
}
//Memory
PdfUtilityCommon utility = new PdfUtilityCommon();
List<byte[]> listaPDF = new List<byte[]>();
listaPDF.Add(applicationPDFData);
MemoryStream ms = utility.MergePdfForms(listaPDF);
return ms;
}
but i have a runtime error because the controllercontext is null
Anyone can help me?
If you take a look at ControllerContext class documentation, it is expected to has HTTP request information. As you have instantiated this controller, there is no related HTTP request, so the context has no data.
Maybe you could try building your own HTTP data on this ControllerContext class. Please, try using this code:
NotificheMezzoPecsController not = new NotificheMezzoPecsController();
RouteData route = new RouteData();
route.Values.Add("action", "createPDFNIR");
route.Values.Add("controller", "NotificheMezzoPecsController");
ControllerContext newContext = new ControllerContext(new HttpContextWrapper(System.Web.HttpContext.Current), route, not);
not.ControllerContext = newContext;
// call controller action
MemoryStream nir = not.createPDFNIR(modelloNIR);
Let me know if it works for you.

'Create copy of work item' via REST API for Azure DevOps?

I'm wanting to 'Create copy of work item' which is available via the UI, ideally via the API.
I know how to create a new work item, but the feature in the UI to connect all current parent links / related links, and all other details is quite useful.
Creating via this API is here: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/create?view=azure-devops-rest-5.1
Any help would be greatly appreciated.
We cannot just copy a work item because it contains system fields that we should skip. Additionally your process may have some rules that may block some fields on the creation step. Here is the small example to clone a work item through REST API with https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client:
class Program
{
static string[] systemFields = { "System.IterationId", "System.ExternalLinkCount", "System.HyperLinkCount", "System.AttachedFileCount", "System.NodeName",
"System.RevisedDate", "System.ChangedDate", "System.Id", "System.AreaId", "System.AuthorizedAs", "System.State", "System.AuthorizedDate", "System.Watermark",
"System.Rev", "System.ChangedBy", "System.Reason", "System.WorkItemType", "System.CreatedDate", "System.CreatedBy", "System.History", "System.RelatedLinkCount",
"System.BoardColumn", "System.BoardColumnDone", "System.BoardLane", "System.CommentCount", "System.TeamProject"}; //system fields to skip
static string[] customFields = { "Microsoft.VSTS.Common.ActivatedDate", "Microsoft.VSTS.Common.ActivatedBy", "Microsoft.VSTS.Common.ResolvedDate",
"Microsoft.VSTS.Common.ResolvedBy", "Microsoft.VSTS.Common.ResolvedReason", "Microsoft.VSTS.Common.ClosedDate", "Microsoft.VSTS.Common.ClosedBy",
"Microsoft.VSTS.Common.StateChangeDate"}; //unneeded fields to skip
const string ChildRefStr = "System.LinkTypes.Hierarchy-Forward"; //should be only one parent
static void Main(string[] args)
{
string pat = "<pat>"; //https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate
string orgUrl = "https://dev.azure.com/<org>";
string newProjectName = "";
int wiIdToClone = 0;
VssConnection connection = new VssConnection(new Uri(orgUrl), new VssBasicCredential(string.Empty, pat));
var witClient = connection.GetClient<WorkItemTrackingHttpClient>();
CloneWorkItem(witClient, wiIdToClone, newProjectName, true);
}
private static void CloneWorkItem(WorkItemTrackingHttpClient witClient, int wiIdToClone, string NewTeamProject = "", bool CopyLink = false)
{
WorkItem wiToClone = (CopyLink) ? witClient.GetWorkItemAsync(wiIdToClone, expand: WorkItemExpand.Relations).Result
: witClient.GetWorkItemAsync(wiIdToClone).Result;
string teamProjectName = (NewTeamProject != "") ? NewTeamProject : wiToClone.Fields["System.TeamProject"].ToString();
string wiType = wiToClone.Fields["System.WorkItemType"].ToString();
JsonPatchDocument patchDocument = new JsonPatchDocument();
foreach (var key in wiToClone.Fields.Keys) //copy fields
if (!systemFields.Contains(key) && !customFields.Contains(key))
if (NewTeamProject == "" ||
(NewTeamProject != "" && key != "System.AreaPath" && key != "System.IterationPath")) //do not copy area and iteration into another project
patchDocument.Add(new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/" + key,
Value = wiToClone.Fields[key]
});
if (CopyLink) //copy links
foreach (var link in wiToClone.Relations)
{
if (link.Rel != ChildRefStr)
{
patchDocument.Add(new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/relations/-",
Value = new
{
rel = link.Rel,
url = link.Url
}
});
}
}
WorkItem clonedWi = witClient.CreateWorkItemAsync(patchDocument, teamProjectName, wiType).Result;
Console.WriteLine("New work item: " + clonedWi.Id);
}
}
Link to full project: https://github.com/ashamrai/AzureDevOpsExtensions/tree/master/CustomNetTasks/CloneWorkItem

retrieve checkbox values and mark as checked

i'm trying to retrieve options from database to checkbox and if it has the same product ID it has to be checked by default
this is the insert code to database
for (int i = 0; i < ddlcaroptions.Items.Count; i++)
{
if (ddlcaroptions.Items[i].Selected == true)
{
Int64 PCarOptionID = Convert.ToInt64(ddlcaroptions.Items[i].Value);
SqlCommand cmd2 = new SqlCommand("insert into tblCarOptionQuant values('" + PID + "','" + PCarOptionID + "')", con);
cmd2.ExecuteNonQuery();
}
}
it works fine now i want to edit this checkbox and update database
now i bind the checkbox from another table that has name and values
SqlCommand cmd = new SqlCommand("select * from tblCarOption", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count != 0)
{
ddlcaroptions.DataSource = dt;
ddlcaroptions.DataTextField = "CarOptionNameAR";
ddlcaroptions.DataValueField = "CarOptionID";
ddlcaroptions.DataBind();
}
now i have all the options but i want the selected values to be the ones that user already checked before and saved in tblCarOptionQuant table,
i tried to get the values by this command
using (SqlCommand getselectedop = new SqlCommand("select PCarOptionID from tblCarOptionQuant where PID = " + PID + "", con))
its okay but now what can i do to set selected values from this command result !??
you can use FindByValue to get the specific item and set it to selected, refer the code below
string value = "SomeValue";
var item = ddlcompany.Items.FindByValue(value);
if (item != null)
item.Selected = true;
the problem is when you retrieve data and convert to string you get only 1st row so i used StringBuilder to build 1 string has all rows in table :)
!! Attention !!
before you use this code make sure you bind your checkbox with all the values that user checked or not ,, then use this code to get the options that selected before (by the user)
using (SqlCommand getselectedop = new SqlCommand("RetrieveCarOptions", con))
{
getselectedop.CommandType = CommandType.StoredProcedure;
getselectedop.Parameters.AddWithValue("#PID", Convert.ToInt64(Request.QueryString["PID"]));
con.Open();
using (SqlDataReader reader = getselectedop.ExecuteReader())
{
StringBuilder sb = new StringBuilder();
if (reader.HasRows)
{
if (sb.Length > 0) sb.Append("___");
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
if (reader.GetValue(i) != DBNull.Value)
sb.AppendFormat("{0}-", Convert.ToString(reader.GetValue(i)));
SelectCheckBoxList(reader["PCarOptionID"].ToString(), ddlcaroptions);
}
}
}
}
now split and check if it has the same value to mark as checked
private void SelectCheckBoxList(string valueToSelect, CheckBoxList ddlcaroptions)
{
string[] aray = valueToSelect.Split(',');
foreach (string listItem2 in aray)
{
ListItem listItem = ddlcaroptions.Items.FindByValue(valueToSelect);
listItem.Selected = true;
}
}
i hope this answer is clear and help someone else :)

Showing Error Value Cannot be null. While Adding Task from Gantt Chart for ASP.NET MVC with dhtmlxGantt

Showing Error Value Cannot be null. While Adding Task from Gantt Chart for ASP.NET MVC with dhtmlxGantt.
An exception of type ‘System.ArgumentNullException’ occurred in mscorlib.dll but was not handled in user code.
Additional Information :Value cannot be null
LINK : dhtmlx Link for Gantt Chart
Heres My Code :
public static List<GanttRequest> Parse(FormCollection form, string ganttMode)
{
// save current culture and change it to InvariantCulture for data parsing
var currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
var dataActions = new List<GanttRequest>();
var prefixes = form["ids"].Split(',');
foreach (var prefix in prefixes)
{
var request = new GanttRequest();
// lambda expression for form data parsing
Func<string, string> parse = x => form[String.Format("{0}_{1}", prefix, x)];
request.Mode = (GanttMode)Enum.Parse(typeof(GanttMode), ganttMode, true);
request.Action = (GanttAction)Enum.Parse(typeof(GanttAction), parse("!nativeeditor_status"), true);
request.SourceId = Int64.Parse(parse("id"));
// parse gantt task
if (request.Action != GanttAction.Deleted && request.Mode == GanttMode.Tasks)
{
//--HERE SHOWING ERROR VALUE CANNOT BE NULL--//
request.UpdatedTask = new GanttTasks()
{
GanttTaskId = (request.Action == GanttAction.Updated) ? (int)request.SourceId : 0,
Text = parse("text"),
StartDate = DateTime.Parse(parse("start_date")),
Duration = Int32.Parse(parse("duration")),
Progress = Decimal.Parse(parse("progress")),
ParentId = (parse("parent") != "0") ? Int32.Parse(parse("parent")) : (int?)null,
SortOrder = (parse("order") != null) ? Int32.Parse(parse("order")) : 0,
Type = parse("type")
};
}
// parse gantt link
else if (request.Action != GanttAction.Deleted && request.Mode == GanttMode.Links)
{
request.UpdatedLink = new GanttLinks()
{
GanttLinkId = (request.Action == GanttAction.Updated) ? (int)request.SourceId : 0,
SourceTaskId = Int32.Parse(parse("source")),
TargetTaskId = Int32.Parse(parse("target")),
Type = parse("type")
};
}
dataActions.Add(request);
}
// return current culture back
Thread.CurrentThread.CurrentCulture = currentCulture;
return dataActions;
}
}
I Referred to link provided above and done as stated. But while adding value its shows value cannot be null.
Try setting a default value for task.progress on the client side,
JS:
gantt.attachEvent("onTaskCreated", function(task){
task.progress = 0;
return true;
});
Client doesn't set the default value for progress property of a newly created task, so when you insert task on a backend progress value is null.
And since backend code doesn't validate the value, probably the error fires on this line:
Progress = Decimal.Parse(parse("progress")),
Setting a default value on the client, as shown above, or checking for null on the server should fix the issue

odata TreeTable with empty row because of slash?

I have a TreeTable which shows data from oData service. Some of the data fields contains symbols of slash ("/", f.e. cats/dogs). My service understands them like a new kind of parameter and doesn't display them in a TreeTable (gives a blank row).
Here is my code:
oData = new sap.ui.model.odata.ODataModel(".../categories/categories.xsodata/", false);
oData.read("/Categories/",
null,
null,
false,
function(oData, oResponse){
flat = {};
for (var i = 0; i < oData.results.length; ++i) {
var item, group, type, code;
var getSubNode = function(obj, key) {
if (!obj[key]) {
obj[key] = {'NAME': key}
}
return obj[key];
};
item = oData.results[i];
group = getSubNode(flat, item.PET_GROUP);
type = getSubNode(group, item.PET_TYPE);
item.NAME = item.GENDER;
item.__metadata = "";
type[item.GENDER] = item;
}
data = {flat : flat,};
});
ojModel = new sap.ui.model.json.JSONModel();
ojModel.setData(data);
oTable.setModel(ojModel);
oTable.bindRows("/flat");
return oTable;
Maybe there is a solution for this?

Resources