Reload specific controls after a child window closes - c#

I have a C# web application using master page...content page...usercontrol that contains a radgrid. To edit a record in that radgrid I launch an custom edit form into a radwindow using a custom url set in the itemcreated event. The edit form contains various controls but at the end of the edit form I will have 2 textboxes and a button. If the user needs to change the values of those 2 textboxes they must click the button to open another .aspx form with usercontrol in a radwindow to perform various database operations to retrieve the new values. I am saving the 2 values into Session so they will be available across the application. My question is how can I implement a delegate to reload the values of just those 2 textboxes when I close the child form. I am not as up on delegates as I need to be.
Thanks

How about having the specific controls listen for the child window closed event?
before you launch the child window add this code:
childwindow.FormClosed += new EventHandler(child_Closed)
then have a class function like this:
void Form117_Load(object sender, EventArgs e)
{
myControl.Text = Session["myControlText"];
myControl2.Text = Session["myControl2Text"];
}

Related

How to access button_click event in parent form from an inherited form in C#?

In my windows form application, I have a main form with toolstrip menu items and buttons that trigger specific inherited forms and open them in the dock window. On the main form, the categoriesToolStripMenuItem open the categories form which is an inherited form where user can perform CRUD operation on the data.
Another inherited form is the products form where user have to choose a specific category from the combobox and add products to that category or edit and delete an existing product from that specific category. To keep the application up and running, I want the user not to be able to open the products form if there is no category added yet. Instead, I want him to add a category before adding products to it.
As soon he click on the button that open product's form, I wan't the click event of categoriesToolStripMenuItem to be triggered if no categories are present in the database. Following is the categoriesToolStripMenuItem click event.
public void categoriesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (fCategories == null)
{
fCategories = new frmCategories();
fCategories.Show(dp, WeifenLuo.WinFormsUI.Docking.DockState.Document);
}
else
{
fCategories.Activate();
}
}
On my Product_Load event, I want to trigger the categoriesToolStripMenuItem on the top like this but it is not triggering like I need it to be:
private void frmProducts_Load(object sender, EventArgs e)
{
FillGrid();
DataTable dt = DataAccess.Select("select categoryname from categories order by categoryname");
if (dt.Rows.Count == 0)
{
frmMain mainForm = new frmMain();
categoriesToolStripMenuItem_Click(sender, e);
return;
}
}
Is there any way to access this event?
Keep in mind that the Load event will only happen the first time the form is loaded (in other words when it is first created). If you are hiding it and showing it your Load handler will not be called. You would probably be better off handling the VisibleChanged event to trigger categories.
Also, calling the Click handler directly is not wrong, but you could also call categoriesToolStripMenuItem.PerformClick() if you have access to the button itself. Then you don't need to worry about sending a sender nor eventArgs and all subscribers to the Click will get called.

How to access the txt info inside a ToolTip from a programmatically created button?

I have problems to access the string inside a programmatically created button. Have a program which reads from a database and shows in a visual form, with buttons, the info of a specific process. Afterwards I want to make available this info with a "click" and show it in a window of the Form.
I create the button (boton1) programmatically, reading registers in a database (the number of buttons created depends of the registers and their values), and in the same step I create a new nutton I create their Tooltip (Tooltip1). So at the end I have a grid of buttons where I can see their tooltips if I haver the mouse over them. What I need is to be able to press these buttons and show in a textbox the info of these specific button's tooltip. The problem is because the boton1 creation is inside a method which creates the grid it's not accesible (I think this is the reason) from a method_click so the button (boton1) or Tooltip1 doesn't exists inside the button_click event, and if I create them it doesn't show when I click the Tooltip1 info but an empty string...
This is my code with the empty string, it doesn't show the info I see in the tooltips but "..." when I "click" on them.
protected void boton1_Click(object sender, EventArgs e)
{
ToolTip Tooltip1 = new ToolTip();
//This Tooltip is already created in other part of the code but without the code "running" don't exist for the button event creation
Button boton1 = sender as Button;
//Same here, already working and the tooltips seems fine but don't exist in the button_click event
//identify which button was clicked and perform necessary actions
String txtTool = tool.GetToolTip(button);
String info = Tooltip1.GetToolTip(boton1);
}

Load same instance in C#.net

I am facing a problem in my application. There are multiple forms which can be accessed by quick setup button in the home page,which contains next and back buttons.
And in the last form there is a finish button, which when clicked goes to another form named Scoreboard. The scoreboard form is having a user control which have home button, setting etc.
When I click on home button it goes back to home page and then when the user clicks the quick setup again, I needs to retain the previous values in the form instead of creating new instance.
In the finish button i am using this code :
Scoreboard sc = new Scoreboard();
sc.show();
this.hide();
Any suggestions ?
There are a couple of ways that you can go. The first is since you are loading your Scoreboard form from the same button you can just subscribe to the Scoreboard Forms FormClosing Event and use public properties to get the information back into your parent form, you could then pass that information back to the ScoreBoard when you create the Form. Your other option would be to use UserSettings to persist your values in between sessions.

How to refresh a current form in C#?

I am creating a multiple form windows application using C#, I have two form one Parent form and a child form.
From parent form I called the child form to add a tree node in the parent form treeview. After entering the details in the child form and pressing "Add" button I want to close the child form and want to add the tree node in the treeview dynamically inside the parent form.
The value is passing perfect, I am using properties for the transfer. Rest by using this.Show() another parent form opens up. I have already tried Invalidate() and Refresh() but the treeview does not get updated.
Override child form constructor to accept parent form as parameter
ChiildForm chilForm=new ChildForm(parentFormObject);
Now you can call method of parent form that would make the required change on the page.
parentFormObject.RefreshSection();
but the treeview does not get updated
To refresh the treeview you need to rebind it to your datasource after adding the newly added item of child form.
Example:
List<SomeClass> items = new List<SomeClass>();
if(childForm.ShowDialog() == DialogResult.Ok)
{
items.Add(childForm.newlyAddedItem); //you have mentioned that values are passing perfect
//your code for rebinding to the treeview
}
If you want to refresh after clicking Add buttons,
just try to call the load_ function by sending the parameters.
example,
button_click(Object sender,Event_args e)
{
Form_Load(sender,e);
}

How to refresh user control grid by using another user control event

I am developing windows application using C#. Need solution for below mentioned scenario. I have windows form containing two user control. First user control contains grid and when user click on any row of grid another user control display details of selected cell. when I modify any data from details control I need to refresh data grid in parent control.
I am using below code to load child control.
private void GridInquiry_CellClick(object sender, DataGridViewCellEventArgs e)
{
PanelParentControl.Controls.Clear();
InquiryDetailsCls.InquiryID = Convert.ToInt32(GridInquiry.SelectedRows[0].Cells[0].Value.ToString());
CtrlInqDetails inqDetails = new CtrlInqDetails(InquiryDetailsCls.InquiryID, 1);
inqDetails.Dock = DockStyle.Fill;
PanelParentControl.Controls.Add(inqDetails);
}
I can recommend to you to use the Notification Center for C#,With this you can make a global event, register for this event anywhere in you code and to fire this event from anywhere in your code.

Categories