I am trying to create a dropdown so that users can see the names of accounts. How do i do that using DevExpress DropDown Button?
You should associate the drop-down button with a popup control/context menu. To accomplish this task use the DropDownControl property.
DXPopupMenu menu = new DXPopupMenu();
menu.Items.Add(new DXMenuItem("Admin"));
menu.Items.Add(new DXMenuItem("Guest"));
// ... add more items
dropDownButton1.DropDownControl = menu;
// subscribe item.Click event
foreach(DXMenuItem item in menu.Items)
item.Click += item_Click;
// setup initial selection
dropDownButton1.Text = menu.Items[0].Caption;
//...
void item_Click(object sender, EventArgs e) {
// synchronize selection
dropDownButton1.Text = ((DXMenuItem)sender).Caption;
// ... do something specific
}
The following objects can be used as popup controls:
PopupMenu - represents a popup menu managed by a BarManager or RibbonControl component.
PopupControlContainer - represents a container for other controls. This control is also managed by a BarManager component.
DXPopupMenu - represents a popup menu.
Related
I am a student learning xamarin forms, I am trying to create a basic chat app in this I want to know how to get position of current item in listview that's user watching. When a new message received i want to know if user is at bottom or not if at bottom focus the new and if not at the bottom then just add not by adding focus to it.
you get the selected item from the Xamarin.Forms.ListView.SelectedItem property of your ListView.
If your ListView.ItemSource is of a type that allows using IndexOf you can now do something like
int position = (yourlistview.ItemSource as ObservableCollection<your type>).IndexOf(yourlistview.SelectedItem)
Update:
ok I think i understood what you want.
In most cases more than one item is currently shown when using a listview. So their exists not a single index
but i think you just want to know if the last item of the list is visible/the user has scrolled to the end?
If so ListView has an ItemAppearing event. I use it for example to load more data from an websource if the user scrolled through the first 100 items.
You could do something like this
listview.ItemAppearing += listviewItemAppearing;
listview.ItemDisappearing += listviewItemDisappearing;
bool m_scrolledToEnd;
private void listviewItemDisappearing(object sender, ItemVisibilityEventArgs e)
{
if(e.Item == yourlastiem)
m_scrolledToEnd = false;
}
private void listviewItemAppearing(object sender, ItemVisibilityEventArgs e)
{
if(e.Item == yourlastiem)
m_scrolledToEnd = true;
}
if you realy need to know if a specific index is shown you could create a List<int> m_idxlist;
and in the appearing event add the index of the item to the list
and in the disappearing event remove the index of the item from the list.
Then you will have a list where all indexes of the items currently shown are stored.
From the Documentation
ListView supports selection of one item at a time. Selection is on by
default. When a user taps an item, two events are fired: ItemTapped
and ItemSelected. Note that tapping the same item twice will not fire
multiple ItemSelected events, but will fire multiple ItemTapped
events. Also note that ItemSelected will be called if an item is
deselected.
To detect selecting an item, you can add a method, onSelection:
void OnSelection (object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null) {
return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
}
DisplayAlert ("Item Selected", e.SelectedItem.ToString (), "Ok");
//((ListView)sender).SelectedItem = null; //uncomment line if you want to disable the visual selection state.
}
To disable selection just set the selectedItem to null:
SelectionDemoList.ItemSelected += (sender, e) => {
((ListView)sender).SelectedItem = null;
};
I am creating a touch application on a no-keyboard pc, where I use a PropertyGrid to manage classes to store / save the app configuration.
I need to edit the propertyline's rows with a custom keyboard that I created (not the system's) setting the class as UITypeEditor
Now the custom keyboard is showed when right button is clicked.
Is it possible to show when on the row start edit (like textbox Enter event),
or when the row is selected ?
The editor control which you see in PropertyGrid is a GridViewEdit control which is a child of PropertyGridView which is a child of the PropertyGrid.
You can find the edit control and assign an event handler to its Enter event. In this event, you can find the SelectedGridItem and then call its EditPropertyValue method which is responsible to show the UITypeEditor.
private void propertyGrid1_SelectedObjectsChanged(object sender, EventArgs e)
{
var grid = propertyGrid1.Controls.Cast<Control>()
.Where(x => x.GetType().Name == "PropertyGridView").FirstOrDefault();
var edit = grid.Controls.Cast<Control>()
.Where(x => x.GetType().Name == "GridViewEdit").FirstOrDefault();
edit.Enter -= edit_Enter;
edit.Enter += edit_Enter;
}
private void edit_Enter(object sender, EventArgs e)
{
var item = this.propertyGrid1.SelectedGridItem;
if (item.GetType().Name == "PropertyDescriptorGridEntry")
{
var method = item.GetType().GetMethod("EditPropertyValue",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
var grid = propertyGrid1.Controls.Cast<Control>()
.Where(x => x.GetType().Name == "PropertyGridView").FirstOrDefault();
method.Invoke(item, new object[] { grid });
}
}
Note: For modal editors the Enter event is annoying and repeats over and over again. To avoid this you can use Click event of the control.
Also as another option you can rely on SelectedGridItemChanged event of PropertyGrid and check if e.NewSelection.GetType().Name == "PropertyDescriptorGridEntry" then call EditPropertyValue of the selected grid item using reflection.
I have two views of WPF (Vista1.xaml and Vista2.xaml), and they are part of a MainWindow.xaml.
In the Vista1.xaml i have a listview, where the user selects some items by clicking and the Vista2.xaml has a button.
I want that when the user clicks on the button of Vista2.xaml, get the items that the user previously selected in the listview of Vista1.xaml.
I have class in the Vista1.xaml.cs ListViewItem_PreviewMouseLeftButtonDown method that captures the user selects the item in the listview.
the code is as follows
private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var item = sender as ListViewItem;
if (item != null && item.IsSelected)
{
...
}
}
I appreciate your help
Add a public property to you MainPage that contains the data you want to pass between Vista1 and Vista2. Then, in your event handler of Vista1, set the property and on the button click of Vista2 read the property.
If I have a context menu with sub menu items, is it possible to stop the sub menu from popping out/displaying when I merely hover over the main menu item? And if so, how?
Each ToolStripDropDownItem has a property called DropDown (of type ToolStripDropDown) referring to the drop down which will be shown when the mouse hovers on the item. The ToolStripDropDown has an event called Opening which allows you to cancel the dropping-down easily. Use the following code, all can be set up in your form constructor:
//Suppose the item you want to suppress automatically showing
//the drop down is item1
bool clicked = false;
item1.DropDown.Opening += (s,e) => {
e.Cancel = !clicked;
clicked = false;
};
item1.Click += (s,e) => {
clicked = true;
item1.ShowDropDown();
};
//The code above disables the automatic dropping-down
//and shows the drop down by clicking on the item1.
I have a List of strings that is regenerated every 5 seconds. I want to create a Context Menu and set its items dynamically using this list.
The problem is that I don't have even a clue how to do that and manage the Click action for every item generated (which should use the same method with different parameter DoSomething("item_name")).
How should I do this?
Thanks for your time.
Best regards.
So, you can clear the items from the context menu with:
myContextMenuStrip.Items.Clear();
You can add an item by calling:
myContextMenuStrip.Items.Add(myString);
The context menu has an ItemClicked event. Your handler could look like so:
private void myContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
DoSomething(e.ClickedItem.Text);
}
Seems to work OK for me. Let me know if I misunderstood your question.
Another alternative using a ToolStripMenuItem object:
//////////// Create a new "ToolStripMenuItem" object:
ToolStripMenuItem newMenuItem= new ToolStripMenuItem();
//////////// Set a name, for identification purposes:
newMenuItem.Name = "nameOfMenuItem";
//////////// Sets the text that will appear in the new context menu option:
newMenuItem.Text = "This is another option!";
//////////// Add this new item to your context menu:
myContextMenuStrip.Items.Add(newMenuItem);
Inside the ItemClicked event of your myContextMenuStrip, you can check which option has been chosen (based on the name property of the menu item)
private void myContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ToolStripItem item = e.ClickedItem;
//////////// This will show "nameOfMenuItem":
MessageBox.Show(item.Name, "And the clicked option is...");
}