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.
Related
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);
}
I am developing a DLL which is loaded into a Tab page in a Enteprise application.
A ListBox control (single select) has an event on listBox_SelectedValueChanged where the use choosed between different "Display Styles" which when changes fires a sub-routine to reload a DataViewGrid control with different information. Code is below for this:
private void listBox_SelectedValueChanged(object sender, EventArgs e)
{
MessageBox.Show("LBSVC Value:" + listBoxDisplayStyles.SelectedValue + " -- Index:" + listBoxDisplayStyles.SelectedIndex);
if (listBoxDisplayStyles.SelectedValue != null)
PatientChanged(true); // true = force a refresh
}
Now inconsistently when finished interacting with DGV control (no editing, just scrolling and ToolTip triggering to show extended information on the cells) I move the mouse back over the listbox control and click a different line to. The new listbox line becomes current (selection bar appears), but the event does not seem to be triggered (ie the MessageBox does not appear and nothing happens.
Why don't you try SelectedIndexChanged event instead. Therein you can still use listBox.SelectedValue to fetch current value and act accordingly.
BTW it looks like you're working with more than one ListBox here. The event handler uses the object name listBox whereas the event body uses listBoxDisplayStyles. That might have something to do with the problem you're facing. But first try SelectedIndexChanged and let us know.
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"];
}
I'm having a Picture box in a user control window(Windows custom control library). and some functionality in the Form's Enter event and leave event.
Now my sample application is having two instances of the control. So when i run my sample application the fist control got selected and the enter event is triggered, and when i select the second control the first's leave and second's enter events are getting triggered.
Now, problem is that when i select(click) the second control's picturebox, the events are not triggering, i.e the control form is not getting the event.
So if i click whereever in the control(in the picturebox or in the control) the enter event should be triggered.
How to do this?
A picture box can't get focus. So clicking on it won't take the focus away from the previous control thus not triggering the events.
You need to add a click handler on the picture box in which you manually give focus to the associated focusable control.
private void PictureBox_Click(object sender, EventArgs e)
{
focusableControl.Focus();
}
I have a custom user control on my windows forms. This control has a few labels on it.
I will be dynamically displaying an array of these controls on my form which will contain different bits of data.
What I am trying to do is know which user control was selected when I click on it.
This works when I click on an empty space on the user control, however, if I click on any label on the user control it will not recognize the user control click.
Any thoughts on how I can do a full user control click, even if a label on the control is being clicked?
If this question is not clear, or you need more info, please leave a comment.
I am doing this in c#.
Thanks!
User control's click event won't fire when another control is clicked on the user control. You need to manually bind each element's click event. You can do this with a simple loop on the user control's codebehind:
foreach (Control control in Controls)
{
// I am assuming MyUserControl_Click handles the click event of the user control.
control.Click += MyUserControl_Click;
}
After this piece of code workd, MyUserControl_Click will fire when any control on the user control is clicked.
foreach (Control c in this.Controls)
{
c.Click += new EventHandler(SameAsForm_Click);
}
Keep in mind that this won't add labels' clickevents in groupboxes, panels etc to the "SameAsForm_Click"-EventHandler.