Unable to use drag Drop in radtreeview - radtreeview

I have binded all data to RadTreeView but unable to use drag-'n-drop. I used four properties as
IsDragDropEnabled="True"
IsDropPreviewLineEnabled="True"
AllowDrop="True"
IsDragPreviewEnabled="True"
and I want to drop an item within same tree. But it doesnt work.

There is quite a bit of info here : http://www.telerik.com/help/silverlight/raddraganddrop-events.html
But I'm also having trouble with the tree view.

After a quick read of this telerik article, drag-drop seems to be working quite well for me.
<telerik:RadTreeView ... EnableDragAndDrop="true" OnNodeDrop="MyTreeView_NodeDrop">
EnableDragAndDrop and OnNodeDrop seem to be the two vital pieces to getting it working, but weren't in your list of attributes you tried. HTH

<telerik:RadTreeView x:Name="treeView1" IsDragDropEnabled="True" Margin="2,0,0,0" ItemsSource="{Binding SelectedSectionList, Mode=TwoWay}" ItemTemplate="{StaticResource SectionTemplate}" IsEditable="True" SelectedItem="{Binding SelectedCustomSectionList, Mode=TwoWay}" Grid.Column="2">
Now in the code behind
You have to fire event
In Constructor
this.treeView1.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);
Then
private void OnDropQuery(object sender, DragDropQueryEventArgs e)
{
RadTreeViewItem destinationItem = e.Options.Destination as RadTreeViewItem;
object source = this.GetItemFromPayload<object>(e.Options.Payload);
object target = destinationItem != null ? destinationItem.Item : null;
DropPosition position = destinationItem != null ? destinationItem.DropPosition : DropPosition.Inside;
if (source != null && target != null)
{
Section sourceSection = source as Section;
Section targetSection = target as Section;
Question sourceQuestion = source as Question;
Question targetQuestion = target as Question;
if (sourceQuestion != null)
{
try
{
if (sourceQuestion != null && targetQuestion != null && object.ReferenceEquals(sourceQuestion, targetQuestion))
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
if (targetQuestion != null && position == DropPosition.Inside)
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
if (position != DropPosition.Inside && targetQuestion == null)
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
}
catch (Exception ex)
{
}
}
}
else
{
e.QueryResult = false;
return;
}
e.QueryResult = true;
}
This is it. You will be able to drag and drop.

Related

AngularJS Selects Empty Option Even Valid Option is Avaliable

I'm using AngularJS ver. 1.2.15 on my project. And, I have a select element on one of my views as per below:
<select class="select-white form-control form-select" id="cat2_{{feed.id}}" ng-model="feed.operationstatusid" ng-change="updateCategoryAndStatus(feed, true)"></select>
And, I'm feeding this element like this:
function SetCategory2(cat1Id, feed) {
var feedId = feed.id;
var fromRuleOpStatusId = -1;
$('#cat2_' + feedId).find('option').remove();
if (cat1Id > -1) {
$('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
$.each($scope.category2, function (index, cat2Item) {
$('#cat2_' + feedId).append($('<option></option>').text(cat2Item.statusdescription).val(cat2Item.id));
});
var isselected = false;
$.each($scope.category2, function (index, cat2Item) {
if (feed.operationstatusid == cat2Item.id) {
$('#cat2_' + feedId).val(cat2Item.id);
fromRuleOpStatusId = -1;
isselected = true;
}
else {
var feedStr = "";
if (feed.title != undefined && feed.title != null) {
feedStr = feed.title.toLowerCase();
}
if ($scope.catTitleRulesTwo) {
$.each($scope.catTitleRulesTwo, function (r_index, r_item) {
if (cat2Item.id == r_item.titleCode && !isselected) {
if (feedStr != undefined && feedStr != null && r_item != undefined && r_item != null) {
String.prototype.contains = function (str) { return this.toLowerCase().indexOf(str) !== -1; };
var text = feedStr;
if (eval(r_item.ruleexpression)) {
$('#cat2_' + feedId).val(cat2Item.id);
fromRuleOpStatusId = cat2Item.id;
isselected = true;
}
}
}
});
}
}
});
if (fromRuleOpStatusId != -1) {
feed.operationstatusid = fromRuleOpStatusId;
}
}
else {
$('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
}
}
I am aware of the facts about eval function, but the project I'm working on is quite old, so does the code. Anyway, this is about business logic and quite irrelevant with the thing I'm going to ask (or so I was thinking).
As you can see I'm appending all the options before I set the value of the selectbox with using .val(...). I have also checked that values do match along with the data types. But, when I observe this function step by step, I saw that selected value does show up without flaw. After the code finish with my above mentioned function (SetCategory2), code goes through on of the function located on AngularJS file, named xhr.onreadystatechange. It's not a long function, so I'm sharing it also on below.
xhr.onreadystatechange = function() {
if (xhr && xhr.readyState == 4) {
var responseHeaders = null,
response = null;
if(status !== ABORTED) {
responseHeaders = xhr.getAllResponseHeaders();
response = ('response' in xhr) ? xhr.response : xhr.responseText;
}
completeRequest(callback,
status || xhr.status,
response,
responseHeaders);
}
};
After the code released from this function, respective selectbox's value is pointed at the empty option.
I have run into topics which talks about this behaviour might due to invalid option-value match, but as I described above, I append all my options before deciding the value. So, I can't figure out what I'm missing.
Thank you in advance.

Navigating Windows Phone 8 Pivot

While working on Windows Phone 8 app, we need to restrict user on navigating pivot.
For example, only first two items are available until user make his selection on second item, then third is unlocked, and so on.
I've tried several approaches, and all of them stumble on one thing - setting pivot.SelectedIndex (or pivot.SelectedItem) inside event handler does not changing visual representation of pivot.
What is missing in my approach?
Here is sample code, from one of variants I've tried...
private void ReservationPivot_UnloadingPivotItem(object sender, PivotItemEventArgs e)
{
if (previousSelectedIndex != ((Pivot)sender).Items.IndexOf(e.Item) && !pivotRedirect)
previousSelectedIndex = ((Pivot)sender).Items.IndexOf(e.Item);
else if (previousSelectedIndex == ((Pivot)sender).Items.IndexOf(e.Item))
return;
object tmp;
PhoneApplicationService.Current.State.TryGetValue("PickupAddress", out tmp);
if (e.Item == ((Pivot)sender).Items[1] && tmp == null && !pivotRedirect)
{
MessageBox.Show("Please, select pickup point!");
pivotRedirect = true;
((Pivot)sender).SelectedIndex = previousSelectedIndex;
((Pivot)sender).SelectedItem = ((Pivot)sender).Items[1];
return;
}
PhoneApplicationService.Current.State.TryGetValue("DropOffAddress", out tmp);
if (e.Item == ((Pivot)sender).Items[2] && tmp == null && !pivotRedirect)
{
MessageBox.Show("Please, select dropoff point!");
pivotRedirect = true;
((Pivot)sender).SelectedIndex = previousSelectedIndex;
((Pivot)sender).SelectedItem = ((Pivot)sender).Items[2];
return;
}
if (pivotRedirect)
{
if (((Pivot)sender).SelectedIndex != previousSelectedIndex)
{
pivotRedirect = false;
((Pivot)sender).SelectedIndex = previousSelectedIndex;
}
}
}
Dont have access to visual now but did you try set visible of third pivot item to collapsed and change it to visible when user will select dropooff point ?

Auto manage and protect Created\Updated fields with Entity Framework 5

I want so every added\changed record will have a time stamp of creation\change.
But - so it will be easy to embed and easy to manage - automatically.
Overwrite the 'DbContext' class or embed this in the '.tt' file (Codefirst \ DBFirst)
The code assume so you have the fields 'CreatedOn'\'ModifiedOn' inside the POCO.
If you don't have them, or you have only one - the code will work fine.
Be aware! If you use a extension (as this one) so allow you to do batch updates or changes from a stored procedure - this will not work
EDIT:
I found the source of my inspiration - thanks 'Nick' here
public override int SaveChanges()
{
var context = ((IObjectContextAdapter)this).ObjectContext;
var currentTime = DateTime.Now;
var objectStateEntries = from v in context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)
where v.IsRelationship == false && v.Entity != null
select v;
foreach (var entry in objectStateEntries)
{
var createdOnProp = entry.Entity.GetType().GetProperty("CreatedOn");
if (createdOnProp != null)
{
if (entry.State == EntityState.Added)
{
if (createdOnProp != null)
{
createdOnProp.SetValue(entry.Entity, currentTime);
}
}
else
{
Entry(entry.Entity).Property("CreatedOn").IsModified = false;
}
}
var modifiedOnProp = entry.Entity.GetType().GetProperty("ModifiedOn");
if (modifiedOnProp != null)
{
modifiedOnProp.SetValue(entry.Entity, currentTime);
}
}
return base.SaveChanges();
}

Flash AS3:Multiple function in one key?

Etc: if I press "space" key, inventory opens.But if I press "space" again, inventory should close.What should I use for this kind of thing?I can open it, but cant close.Thanks, sorry for bad english.(P.S: Im using flashdevelop+flixel)
Yes, this is completely possible.
var isInventOpen:Boolean = false;
function openCloseInvent(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.SPACE && isInventOpen == false)
{
//Open Inventory
isInventOpen = true;
}
if(e.keyCode == Keyboard.SPACE && isInventOpen == true)
{
//Close Inventory
isInventOpen = false;
}
}
More info on KeyCodes can be found here: KeyCodes, if you need it.
You should give yourself a boolean, like so:
var menuOpen:Boolean = false;
function yourEventHandler(e:KeyboardEvent):void {
if (menuOpen) {
menuOpen = false;
//close your menu here
} else {
menuOpen = true;
//open menu here
}
}

IWebBrowser2 IHTMLDocument2 CTRL+F dialog appears but finds no matches

I'm generating HTML pages from strings stored in a database by using the IHTMLDocument2 write(SAFEARRAY) method. This works OK.
When CTRL+F is pressed the Find dialog appears as expected, but there are never any matches. What is being searched by CTRL+F? Perhaps an object is missing(that I must create) that the search looks at?
Here's some relevant code:
CComPtr<IDispatch> m_spDisp;
CComPtr<IWebBrowser2> m_spWeb2;
HRESULT m_hr;
IHTMLDocument2* m_document;
BOOL CSwiftDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_BackMenuButton.SetToolTipText(_T("Back"));
m_bInitialised = true;
m_bBackClicked = false;
m_svURLList.clear();
m_nCurrentPage = -1;
m_bitBack.LoadBitmap(IDB_BACK_BITMAP);
m_BackMenuButton.SetBitmap(m_bitBack);
m_spGlobal.CreateInstance(__uuidof(GLOBVARSLib::Global ) );
m_browser.Navigate(CSTR m_sURL, NULL, NULL, NULL, NULL);
GetDocument();
WriteHTMLString();
SetWindowSize(512,384);
return TRUE;
}
void CSwiftDlg::GetDocument()
{
m_hr = S_OK;
m_spDisp = m_browser.get_Application();
if (m_spDisp != NULL && m_spWeb2 ==NULL)
{
m_hr = m_spDisp->QueryInterface(IID_IWebBrowser2,(void**)&m_spWeb2);
}
if (SUCCEEDED(m_hr) && m_spWeb2 != NULL)
{
// get browser document's dispatch interface
IDispatch *document_dispatch = NULL;
m_hr = m_spWeb2->get_Document(&document_dispatch);
if (SUCCEEDED(m_hr) && (document_dispatch != NULL))
{ // get the actual document interface
m_hr = document_dispatch->QueryInterface(IID_IHTMLDocument2, (void **)&m_document);
// release dispatch interface
document_dispatch->Release();
}
}
}
void CSwiftDlg::WriteHTMLString()
{
if (m_document == NULL)
GetDocument();
SAFEARRAY *empty_array = SafeArrayCreateVector(VT_VARIANT,0,1);
// construct text to be written to browser as SAFEARRAY
SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1);
VARIANT *variant;
SafeArrayAccessData(safe_array,(LPVOID *)&variant);
variant->vt = VT_BSTR;
variant->bstrVal = m_sHTML.AllocSysString();
SafeArrayUnaccessData(safe_array);
// write SAFEARRAY to browser document
m_document->write(empty_array);
m_document->close();
m_document->write(safe_array);
}
Answer:
As #Yahia suggested, it was a focus problem. I added m_document->execCommand("Refresh",...) after the m_document->write(safe_array) statement, as when I did "refresh" from the context menu Ctrl-F worked as expected. That fixed the "focus issue".
CTRL+F is focus-aware... you need to call focus on the parentWindow of m_document after WriteHTMLString(); and/or SetWindowSize(512,384);...