How do I refresh a tab control page after a database update - database

Using Visual Studio community 2017, winforms, C# and MySql DB.
I have a tab control page that displays the playlists created from the DB.
When I delete a playlists, it's removed from the DB, but is still visible in the tab page.
I created a button to try all refresh, update scenarios I could think of to no avail.
PlayListLoad() is my function that creates and populates my playlists.
Thanks for your help.
private void RefreshBtn_Click(object sender, EventArgs e)
{
PlayListLoad();
tabPage3.Update();
tabPage3.Refresh();
}

Found the answer through a lot of searches and try/error.
I just needed to clear the controls before updating.
private void RefreshBtn_Click(object sender, EventArgs e)
{
tabPage3.Controls.Clear();
PlayListLoad();
tabPage3.Update();
tabPage3.Refresh();
}

Related

Wpf webbrowser disable external links

elI am working on a Wpf application. it contains a webbrowser where the user authenticates via Facebook. The problem is that the user is capable of clicking on links (for example: Forgot your password?) the standaard browser then open... what i want to do is to disable/block all the external links. so users can only authenticate and not navigate through the webbrowser control. I hoop you guys can help me out.
Update 1
Like suggested i can check the source of the webbrowser. So i can allow the wanted pages. but the problem are the links. they open on IE. i dont want to open them, but to block them at all
Description image
private void webBrowserFacebook_Navigating_1(object sender, NavigatingCancelEventArgs e)
{
string huidigeLink = Convert.ToString(webBrowserFacebook.Source);
MessageBox.Show(huidigeLink);
// check for allowed pages
}
Update 2
I was able to find a solution: http://social.technet.microsoft.com/wiki/contents/articles/22943.preventing-external-links-from-opening-in-new-window-in-wpf-web-browser.aspx
Very slef explanatory.. thank you guys for the help!
void Window1_Loaded(object sender, RoutedEventArgs e)
{
browser = new WebBrowser();
browser.Navigate(new Uri("http://www.google.com"));
browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating);
browser.Navigated += new NavigatedEventHandler(browser_Navigated);
}
void browser_Navigating(object sender, NavigatingCancelEventArgs e)
{
//Your checks should happen here..
Console.WriteLine("Loading Webpage !!");
}
void browser_Navigated(object sender, NavigationEventArgs e)
{
Console.WriteLine("Webpage Loaded !!");
}
You can register for WebBrowser.Navigating Event.
Navigating event handlers are passed an instance of the NavigatingCancelEventArgs class. You can cancel the navigation by setting the Cancel property of the NavigatingCancelEventArgs object to true.
Or you can invoke script or browser instance to stop loading if URL navigating doesn't matches.
yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");

CRUD with WPF, e.Row.Item and e.Row.DataContext are empty

I'm trying to build simplest CRUD application on Windows desktop.
Decided to go with WPF over Windows Forms and Lightswitch.
Created database, then generated "Code first from database" with Entity Framework.
Put datagrid with one table, set datasource. Run - it worked, I can Read.
Added a button, created Click handler with context.SaveChanges(); - ok, Update works.
Now, cannot get to Create part.
Added
authorsDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if (e.EditAction == DataGridEditAction.Commit)
{
var newAuthor = e.Row.Item as authors;
context.authors.Add(newAuthor);
context.SaveChanges();
}
}
and unfortunately e.Row.Item (or e.Row.DataContext) comes in empty.
Where could be mistake?
WPF/WinForm CRUD tutorial links are welcome; been googling for days, haven't found a good one.
Ok, problem is solved; although original question is not answered, I went another way - created separate button which creates and adds Author based on currently selected item:
private void create_Click(object sender, RoutedEventArgs e)
{
var newAuthor = authorsDataGrid.SelectedItem as authors;
context.authors.Add(newAuthor);
context.SaveChanges();
this.authorsDataGrid.Items.Refresh();
}

WPF ContextMenu click routed to WinForms application

I am writing a WPF control which is hosted in an Word VSTO AddIn (WinForms). Now I have a problem with the mouse click events on a context menu.
If I click on a context menu item on the left half (the part over the WinForms app), the click goes directly to the WinForms app and my context menu does not receive the event.
If I click the right half of the item (part over the WPF form), everything works as expected.
Can someone out there help me solve this issue?
The answer from the inactive blog is:
Declare a class level dispatcher frame object
System.Windows.Threading.DispatcherFrame _frame;
Subscribe to the GotFocusEvent and LostFocusEvent for the menu:
_menu.AddHandler(System.Windows.UIElement.GotFocusEvent,new RoutedEventHandler(OnGotFocusEvent));
_menu.AddHandler(System.Windows.UIElement.LostFocusEvent, new RoutedEventHandler(OnLostFocusEvent));
Below is the implementation for the event procedures for the GotFocusEvent and LostFocusEvent:
private void OnGotFocusEvent(object sender, RoutedEventArgs e)
{
if (LogicalTreeHelper.GetParent((DependencyObject)e.OriginalSource) == _menu)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal (DispatcherOperationCallback)delegate(object unused)
{
_frame = new DispatcherFrame();
Dispatcher.PushFrame(_frame);
return null;
}, null);
}
}
private void OnLostFocusEvent(object sender, RoutedEventArgs e)
{
if (LogicalTreeHelper.GetParent((DependencyObject)e.OriginalSource) == _menu)
{
_frame.Continue = false;
}
}
In my case, the if statements weren't needed and I subscribed to the events like this
<EventSetter Event="GotFocus" Handler="contextMenu_GotFocus" />
<EventSetter Event="LostFocus" Handler="contextMenu_LostFocus" />
After some deep research I stumbled upon the following bug:
https://web.archive.org/web/20101211205036/http://connect.microsoft.com:80/VisualStudio/feedback/details/432998/excel-2007-vsto-custom-task-pane-with-wpf-context-menu-has-focus-problems
It's for Excel 2007, but is still valid for other Office products (2007, 2010). I managed to fix my issue using the method described here:
https://web.archive.org/web/20151231010333/http://blogs.msdn.com/b/vsod/archive/2009/12/16/excel-2007-wpf-events-are-not-fired-for-items-that-overlap-excel-ui-for-wpf-context-menus.aspx

Navigate back button with ssrs in Silverlight app

I have a Silverlight application which has a RadHtmlPlaceholder which points to ssrs to display reports like so:
<telerik:RadHtmlPlaceholder SourceUrl="http://serverName/ReportServer/Pages/ReportViewer.aspx?/Northwind/Employees&rs:Command=render" />
This works fine but when I have a report that allows you to drill down to display a child report, there is no way of getting back to the parent report without having to load the whole lot again. There doesn't seem to be an option to turn on the navigate back button toolbar option and I've seen other ways of implementing a back button by using javascript to set the window location back one in the history, but obviously this won't work in a Silverlight application. Is there anyway to implement a navigate back button?
Take a look at this thread over in the Telerik forums: http://www.telerik.com/community/forums/silverlight/htmlplaceholder/html-place-holder-back-forward-refresh.aspx
Basically you need to get a handle on the IFrame from the presenter and inject some JavaScript. The history object also has a length property you can use to evaluate if your buttons should be enabled.
public MainPage()
{
InitializeComponent();
// Get the IFrame from the HtmlPresenter
HtmlElement iframe = (HtmlElement)htmlPlaceholder.HtmlPresenter.Children[0];
// Set an ID to the IFrame so that can be used later when calling the javascript
iframe.SetAttribute("id", "myIFrame");
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.location.reload(true);";
HtmlPage.Window.Eval(code);
}
private void Back_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.history.back();";
HtmlPage.Window.Eval(code);
}
private void Forward_Click(object sender, RoutedEventArgs e)
{
// Code to be executed
string code = "document.getElementById('myIFrame').contentWindow.history.forward();";
HtmlPage.Window.Eval(code);
}
}

this.Close() won't work

I have a windows forms app (c# 4.0) and the "X" button won't close the form, and this.close() won't do it either.
Other forms work fine, yet when I copy the designer over to a new form, it breaks that form too!
any clues?
so... apparently this makes it work (creating a closing event, and putting in the following code)
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.Dispose();
}

Resources