How to used the e.SelectedControl from the Devexpress Tooltip event - c#

In the Devexpress ToolTipControllerGetActiveObjectInfoEventArgs Event there is a parameter passed to the function.
There is a SelectedControl member variable which points to the DevEx grid control object.
From here I want can get the active GridView (this is because I have several grids coming in here).
Can someone give me some sample code to get from the SelectedControl to the GridView?
private void MyToolTipController_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{

If you want to get the view under the mouse point then you can use GridControl.GetViewAt method.
Here is example:
private void MyToolTipController_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
var gridControl = e.SelectedControl as GridControl;
if (gridControl != null)
{
var view = gridControl.GetViewAt(e.ControlMousePosition);
//Your code here.
}
}
Also, if you want to get the focused view then you can use GridControl.FocusedView property.
Here is example:
private void MyToolTipController_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
var gridControl = e.SelectedControl as GridControl;
if (gridControl != null)
{
var view = gridControl.FocusedView;
//Your code here.
}
}

Related

Main form fields only display data of first item selected within listbox

I have two forms that need to interact with each other. The parent form has 4 fields and an add button that saves data from each field to an instance of a class object. After its saved to an object the object is stored in a listbox, which the child form contains. I created a custom event to handle that stuff, but I am surely doing something wrong.
What's supposed to happen is that when both windows are open, and there is data in the listbox, whatever item that is selected from the child form listbox fills the parent form fields with the data from that object. When I test out my code, only the first item has the data properly filling the correct fields. If I click any other item after the first selection, the main form fields do not update at all.
Specific to my issue the child form has the following codes:
public EventHandler ListBoxItemClicked;
private void pPotionList_SelectedIndexChanged(object sender, EventArgs e)
{
PotionForm tempMain = new PotionForm(); //this was a test, nothing changed
pPotionList.SelectionMode = SelectionMode.One;
if (ListBoxItemClicked != null)
{
ListBoxItemClicked(this, new EventArgs());
}
tempMain.Refresh(); // this too
}
The parent form has these codes
private void pListDisplay_Click(object sender, EventArgs e)
{
PotionList secForm = new PotionList();
secForm.secFormBox.DataSource = potionBindList;
PotionListChanged += secForm.HandlePotionListChanged;
secForm.ChildPotionListChanged += HandleChildPotionListChanged;
secForm.ListBoxItemClicked += HandleListBoxItemClicked; //this line
secForm.Show();
}
public void HandleListBoxItemClicked(object sender, EventArgs e)
{
pTypeInput.SelectedItem = aPotion._type;
pMagInput.Value = aPotion._magnitude;
pNameInput.Text = aPotion._name;
pBonusInput.Checked = aPotion._bonus;
}
I am currently using Visual Studio Community 2015 if that's relevant.
Ok after seeing all the necessary code I would say that the problem is that you never pass the values from the Child-Form to the Parent. Whenever the event HandleListBoxItemClicked is fired only the initial values of aPotion are written to the controls.
As a solution I would suggest to pass the SelectedItem as the sender when you fire the ListBoxItemClicked event in the childform:
CHILD
public EventHandler ListBoxItemClicked;
private void pPotionList_SelectedIndexChanged(object sender, EventArgs e)
{
Potion p = pPotionList.SelectedItem as Potion;
pPotionList.SelectionMode = SelectionMode.One;
if (p != null)
{
if (ListBoxItemClicked != null)
{
ListBoxItemClicked(p, new EventArgs());
}
}
}
Not you can use this information in the parent form and disperse the information as you please:
PARENT
public void HandleListBoxItemClicked(object sender, EventArgs e)
{
Potion p_parent = sender as Potion;
if(p_parent != null)
{
pTypeInput.SelectedItem = p_parent._type;
pMagInput.Value = p_parent._magnitude;
pNameInput.Text = p_parent._name;
pBonusInput.Checked = p_parent._bonus;
}
}
No refresh or anything else should now be necessary. Hope it helps

WPF DataGrid CanUserAddRows event

Is there an event or command I could use so I can invoke the object that is getting added to the ObservableCollection before it gets added?
At the moment, once the user clicks the row in the grid, it adds it to the collection, however I need to specifically assign properties in C# that I don't want to assign in the grid.
public void event
{
// I want to do something before the CanUserAddRow event does this
collection.Add(<T>;
}
You can use DataGrid.InitializingNewItem event:
private void InitializingNewItem(object sender, InitializingNewItemEventArgs e)
{
//use e.NewItem here
}
From MSDN
You can set default values for the new item by handling the InitializingNewItem event and setting the values programmatically
I'm not exactly sure is that work for you...
private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
YourObject obj = e.Row.Item as YourObject;
if (obj != null)
{
//see obj properties
}
}
Explanation :
In here after user enter the data to the grid, and It takes as e.Row.Item Then you can change any of modification to your object.

Do I need to trigger an event for the bind with Combox works properly?

I have an issue with a ComboBox
private void Form_AddGoal_Load(object sender, EventArgs e)
{
LoadGoal();
IList<Perspective> perspectives = PerspectiveRepository.All(); // I get all perspectives
CBPerspective.DataSource = perspectives;
CBPerspective.DisplayMember = "Name";
// Here I initialize other components
}
private void LoadGoal()
{
if (Goal== null)
Goal = new Goal();
// Here I bind other components
CBPerspective.DataBindings.Add("SelectedItem", Goal, "Perspective");
}
public void SaveBtn_Click(object sender, EventArgs e)
{
// I save the Goal
}
When the form is open, all is ok. If I don't choose any option in the combobox (That is, the first option keep it) and I save the data on the form the Perspective property is null but If I choose other option in the combobox and proceed in the same way, perspective is equal to the selected item so works perfectly.
What is going on? Do I need trigger an event?

control not found message is displayed

Error Message displayed as "AddFavoriteRadWindow not found"
My code:
protected void btnAddReport_Click(object sender, ImageClickEventArgs e)
{
this.form1.Controls.Add(AddFavoriteRadWindow); // working fine
}
protected void btnOk_Click(object sender, EventArgs e)
{
if (txtReportFavorite.Text != string.Empty)
{
// code for inserting into db..
AddFavoriteRadWindow.Visible = false; // not working
}
}
"AddFavoriteRadWindow not found" message is displayed when I want to hide the rad window
You need to get the instance of your added controls from your Control Collection. Try
(this.form1.FindControl(AddFavoriteRadWindow.ID) as RadWindow).Visible = false;
You may put a check in place against null. Something like.
if((this.form1.FindControl(AddFavoriteRadWindow.ID) as RadWindow) != null)
(I am not sure about your class name, I have used RadWindow but you can replace that with your class name)
EDIT: You should pass the string id of the control in your FindControl method to get that specific control back

Determine source of event

I have a dropdown list and radio button. If something is selected from the dropdown by the user, I want the radio button cleared. If the radio button is selected I want the selection of the dropdown cleared. Unfortunately, this creates events that cancel each other out. I tried using the sender as shown below to determine if the value was being changed by code or by the user, but that doesn't work. How do I make these events only work if the user is the source of the action?
private void rbBlank_Checked(object sender, RoutedEventArgs e)
{
// Verify source of event
if (sender is RadioButton)
{
// Display
comboBoxTitles.SelectedIndex = -1;
}
}
private void comboBoxTitles_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// Verify source of event
if (sender is ComboBox)
{
// Display
rbBlank.IsChecked = false;
}
}
You won't be able to tell the difference between the two since the source will be the same instance for both occasions.
This doesn't answer the question directly but if you compare the SelectedIndex of comboBoxTitles in the SelectionChanged event handler, your problem should be solved
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBoxTitles.SelectedIndex != -1)
{
rbBlank.IsChecked = false;
}
}
Try to compare if sender == instance of a control instead of is type of.
private void rbBlank_Checked(object sender, RoutedEventArgs e)
{
// Verify source of event
if (sender == rbBlank)
{
// Display
comboBoxTitles.SelectedIndex = -1;
}
}
private void comboBoxTitles_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
// Verify source of event
if (sender == comboBoxTitles)
{
// Display
rbBlank.IsChecked = false;
}
}
If you know the IDs of those controls, you can try something like this:
System.Web.UI.WebControls.WebControl webControl = (System.Web.UI.WebControls.WebControl) sender;
if( webControl.ID == <comboboxId>)
{
//Do something
}
I havent tried this, but I guess it might work.

Categories