When we adding service reference to project sometimes we encounter “object reference is not set to an instance object” error. Sometimes it fix after follow following steps.
Step 1: Check are there any errors in WCF service and if there were errors fix it and retry.
Step 2: If there were existing service reference then delete it and add again.
Step 3: If step 2 not success then delete reference from service reference folder in project location (from hard disc) and try to add reference again.
Step 4: If first three steps not working go to the app config or web config file and remove relevant endpoint settings and try to add again.
Step 5: Host WCF service in iis and add service reference from iis url
Thursday, February 9, 2017
Sunday, January 1, 2017
Kendo Grid Tips: Navigate Kendo Grid CellsUsing Tab Key Based on Row and Column
Some time we have requirements to move user to pre determine cells in the kendo grid based on conditions. As example there were kendo grid after user save data it disable correct cells and enable cells which have errors. User has requirement to move only error cells using tab key.
For such kind of requirements can use following code snippets to navigate user.
Following function used array called “InvalidCells”, when updating cells with results save invalid cells in array use that array to determine nearest invalid cell in the grid.
For such kind of requirements can use following code snippets to navigate user.
$(document).ready(function () {
$("#Grid").on("keyup", 'tr', function (event) {
navigateColorGrid(event);
});
});
function navigateColorGrid(e) {
if (e.keyCode == 9) {
event.stopPropagation();
event.stopImmediatePropagation();
event.preventDefault(); //Prevent default tab key function
var eCell = $(e.target).closest('td');
var currentIndex = eCell.index();
var currentIndexRow = $(e.target).closest('tr').index();
var dataGrid = $('#Grid').data().kendoGrid;
var currentRow = $(e.target).closest('tr');
eCell = $(currentRow).find('td:eq(' + currentIndex + ')');
if (invalidCells.length > 0) {
tabToNextCell(currentIndexRow, currentIndex);
} else {
setTimeout(function () {
var grid = $("#Grid").data("kendoGrid");
if (eCell != null) {
grid.editCell(eCell);
var inputText = eCell.find("input").length;
var cPosition = inputText - 1;
}
}, 10);
}
}
}
function tabToNextCell(currentIndexRow, currentIndex) {
var eCell = $("#Grid").children().find("tbody").find("tr:eq(" + currentIndexRow + ")").find("td:eq(" + currentIndex + ")");
var cellLocation = getNextinvalidCell(currentIndexRow, currentIndex);
if (cellLocation.length > 0) {
var rowNumber = cellLocation[0].rowIndex;
var cellNumber = cellLocation[0].cellIndex;
eCell = $("#Grid").children().find("tbody").find("tr:eq(" + rowNumber + ")").find("td:eq(" + cellNumber + ")");
}
setTimeout(function () {
var grid = $("#Grid").data("kendoGrid");
if (eCell != null) {
grid.editCell(eCell);
eCell.select();
}
}, 10);
}
Following function used array called “InvalidCells”, when updating cells with results save invalid cells in array use that array to determine nearest invalid cell in the grid.
function getNextinvalidCell(currentIndexRow, currentIndex) {
//Current row contains another invalid cell
var cellLocation = [];
var invalidCell = $.grep(invalidCells, function (cell) {
return cell.rowIndex == currentIndexRow && cell.cellIndex > currentIndex;
});
if (invalidCell.length > 0) {
var sortedInvalidCells = invalidCell.sort(function (a, b) {
return a.cellIndex - b.cellIndex;
});
cellLocation.push({ rowIndex: sortedInvalidCells[0].rowIndex, cellIndex: sortedInvalidCells[0].cellIndex })
}
return cellLocation;
}
Sunday, November 20, 2016
Kendo Grid Tips: Adding New Row to Kendo Gird with Enter Key Press
There were requirements to add new row to editable gird when user click on last editable cell. Using addRow() function of kendo gird we can add new row to data gird. However to use that function we need to identify the correct key stroke and correct cell to invoke addRow() function. Following code snippet shows how to add new row to grid if user press enter key on 4th column.
We can change javascript key value to modify following script to trigger on any key (e.g. if change (code == 9) you can add new row with Tab key)
We can change javascript key value to modify following script to trigger on any key (e.g. if change (code == 9) you can add new row with Tab key)
$(document).ready(function () {
$("#MyGrid").on("keyup", "tr", function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
var td = $(e.target).closest('td');
if (code == 13) {
var tdIndex = td.index();
if (tdIndex == 3) {
var grid = $("#MyGrid").data("kendoGrid");
grid.addRow();
}
}
});
});
Monday, September 5, 2016
Change XamDataGrid Cell based on values of other cells in code behind – WPF
Sometimes we have requirement to enable/disable single cell value in data grid based on the selections of other cells.
Scenario:
There were XamDataGrid which user able to add purchasing details for their warehouse. When user purchase materials from different units like (Meters, Kilograms) however user only use Yard in their manufacturing process.
If user select Yard for their unit and they get those materials from Meters, then user need to set Meter to Yard conversion automatically and freeze the conversion cell.
How to implement:
Add value change event to the Unit columns
Based on the conditions user can add any conditions to filter values.
“Conversion” is the column name contains the cell.
Scenario:
There were XamDataGrid which user able to add purchasing details for their warehouse. When user purchase materials from different units like (Meters, Kilograms) however user only use Yard in their manufacturing process.
If user select Yard for their unit and they get those materials from Meters, then user need to set Meter to Yard conversion automatically and freeze the conversion cell.
How to implement:
Add value change event to the Unit columns
<EventSetter Event="igEditors:ValueEditor.ValueChanged" Handler="PUOM_OnValueChanged" />
<EventSetter Event="igEditors:ValueEditor.ValueChanged" Handler="SUOM_OnValueChanged" />Code-behind:
private void SUOM_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
DataRecord dt = (DataRecord)xamGridLines.ActiveRecord;
Cell cellConversion = dt.Cells["Conversion"] as Cell;
var cellEditor = Infragistics.Windows.DataPresenter.CellValuePresenter.FromCell(cellConversion).Editor;
cellEditor.IsReadOnly = true;
}
If user need to inactive entire column use following code
snippet
private void SUOM_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
xamGridLines.FieldLayouts[0].Fields["Conversion"].Settings.AllowEdit = false;
xamGridLines.ActiveRecord.FieldLayout.Fields["Conversion"].Settings.AllowEdit = false;
}
Sunday, January 17, 2016
Bower Tips: Fix Syntax Error in bower.json
Bower is a famous package manager in now a days.
Sometimes while restoring the packages it gives “Malformed bower.json” error.
Once error occurred most of times we only consider the bower config file which added in to the project. However while we adding package to the project it creates its own bower.json file and .bower.json file inside the package. If one of those files are malformed then it gives same malformed error while restoring the packages or while restoring dependencies. Due to that reason we need to check automatically added bower files to identify the root cause of the error. Those automatically added files may be hidden in the solution explorer.
How to fix the error:
Sometimes while restoring the packages it gives “Malformed bower.json” error.
Once error occurred most of times we only consider the bower config file which added in to the project. However while we adding package to the project it creates its own bower.json file and .bower.json file inside the package. If one of those files are malformed then it gives same malformed error while restoring the packages or while restoring dependencies. Due to that reason we need to check automatically added bower files to identify the root cause of the error. Those automatically added files may be hidden in the solution explorer.
How to fix the error:
- If you use visual studio read error output carefully and it mentioned the bower file need to correct.
- Open relevant bower file
- Remove unwanted content from it (all other content which located after main curly braces) and save it then it will fix the Dependency error instantly.
Subscribe to:
Posts (Atom)



