How to make popup menu with right click on GridControl row? - devexpress

I have a GridControl with some rows on my DevExpress interface. When I right-click on some row of the grid I want to pop-up the same kind of menu like when i right-click on my desktop(win 7), but only with 3 options - Cut, Paste and Copy.
How to make this? Is there a way to say in the property editor of the GridControl "for every row if right-click then popup a Menu". If so, is this menu stored in a repository and what type is this menu?

Add a DevXpress.ExtraBars.BarManager Control.
Add a DevXpress.ExtraBars.PopupMenu Control.
Create your menu structure inside the PopupMenu control.
Add this code into the 'PopupMenuShowing' event of your GridView:
private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
if (e.HitInfo.InRow)
{
System.Drawing.Point p2 = Control.MousePosition;
this.popupMenu1.ShowPopup(p2);
}
}
That's It!

Handle the GridView's ShowGridMenu event to show the context menu when a gridRow is clicked. We have also published an example showing how this event can be used:
How to show a context menu for grid rows

Related

how can i acces the control on label text dropdown list event selection in the gridview in asp.net

i want to change the price of the item only whose number of quantity gets changed in the dropdown list .
But i am not able to access the label.text property in the "protected void
DropDownList1_SelectedIndexChanged(object sender, EventArgs e)" event.
the html code of the grid view is as
For the future: Please provide the code as actual text inline with the question instead of a screenshot. You can also add images directly to the question instead of via imgur.
Regarding your problem: You need to use the FindControl method of the Grid like this: GridView1.FindControl(lblprice) to get a reference to the label. With that you can access its text

Dynamically created link button event not firing after page index change

I have dynamically created link buttons in grid view and assigning event for it,
lb.Click += new EventHandler(LinkButtonClicked);
Event is not firing if I change page index change (on click of '2' below grid view) and click on link button present in grid view.
It is working fine if I do not change the page index i.e. without clicking on '2' of grid view, clicking on link button present in grid view
I am not able to find out reason for this. Please help
Thanks in advance!
I think it is better to create the linkbutton inside markup in a grid template column.
if you have to do it in code, try to unsubscribe the event handler then subscribe again:
lb.Click -= new EventHandler(LinkButtonClicked);
lb.Click += new EventHandler(LinkButtonClicked);

Select checkbox of gridview with keyboard in asp.net

I am using GridView on my page, which retrieves data from SQL database.
The first column is named OK and has a Checkbox in each row.
I want to select each check box with the help of keyboard instead of mouse.
The shortcut for toggling a checkbox is the spacebar, so as long as you have the checkbox highlighted, you can use that to check each box.
Next, check out some articles on adding GridView keyboard navigation:
GridView column and row navigation using up/down/right and left arrows
GridView Rows Navigation Using Arrow (Up/Down) Keys
GridView Up and Down Navigation using jQuery

With the Ajax Control Toolkit, how would I go about programmatically creating an accordion control that is resizeable and drag/droppable at runtime?

I was trying to generate a resizable and drag/droppable ajax control toolkit accordion control programmatically, but am running into some problems.
First, can it be done?
Second, my approach is not exactly working.
I have a button that, OnClick, is supposed to create the accordion. So I create the accordion. Add an accordion pane to it. Add a combo button to the accordion pane. Then add the entire accordion to the Ajax Panel. My event handler follows.
protected void btnTest_Clicked(object sender, EventArgs e)
{
//Generate the accordion
AjaxControlToolkit.Accordion acc = new AjaxControlToolkit.Accordion();
//Generate a single accordion pane
AjaxControlToolkit.AccordionPane itm = new AccordionPane();
//Create and add a control to the pane
AjaxControlToolkit.ComboBoxButton cbbtn = new ComboBoxButton();
itm.Controls.Add(cbbtn);
acc.Panes.Add(itm);
//Add resizable extender to the accordion. Only did resizable for now.
//One step at a time.
AjaxControlToolkit.ResizableControlExtender extResizeLocation = new AjaxControlToolkit.ResizableControlExtender();
extResizeLocation.TargetControlID = acc.ID;
extResizeLocation.Enabled = true;
//Add accordion to update panel and update.
UpdatePanel1.Controls.Add(acc);
UpdatePanel1.Update();
}
What I get when I press the test button is what appears to be a minimized button without text generated under the test button. I have no clue what to do.
Appreciate the help
Dynamically added controls are typically supposed to be added during init or preinit event of the page. That may be a complication, since you are doing it after load.
The key is to make sure the $register method on the client for the accordion is occurring. This is what initializes the client-side features of the AJAX component, and starts the lifecycle. I don't know if it happens for dynamically added controls...
You may want to look at the JQuery UI Accordian widget and use the draggable/droppable interactions.
You could use server side code to create an block and apply the jQuery interaction.

Editing row of a datagrid in ASP.Net VB.Net

I'm working on a piece of code at the moment that uses an older style DataGrid to allow the user to enter information into the table. It already has an add and delete button. Currently the user enters information into 3 textboxes that are in the footer, and the other rows use labels to display the information.
Essentially what I am wanting to do is take the line that the user has clicked the edit button on, and move the text from there in to the footer (deleteing the row that it was displayed on) so the user can make changes and then click the add button again. At the moment I have tried using FindControls to find the textbox and setting the text that way but it doesnt like it. Any ideas?
A few things need to be clarified - are you referring to the older .NET "DataGrid" control or the newer "GridView" control. Also, is this a web or winforms app?
My suggestions -
Have you tried to programmatically add and set the TextBox controls by handling the GridView1_RowEditing event?
To remove the row that's been edited - remove it from the datasource and rebind the grid.
list.Remove(itemToRemove);
GridView1.DataSource = list;
GridView1.DataBind();
Then, take the data from itemToRemove and use it to programmatically create and set textboxes in the footer.
If the third column of your data grid is called "Name" and contains the name data, you would create and set the third column's footer row TextBox value like this -
GridView1.FooterRow.Cells[2].Controls.Add(new TextBox { ID = "tbName", Text = item.Name });
How are you using FindControl? It always helps to post your code ;)
You should be able to execute a FindControl() on the footer row and get the textboxes with no problem.
GridViewRow row = GridView1.FooterRow;
TextBox txt1 = ((TextBox)row.FindControl,"TextBox1"));
Essentially I changed what I had originally planned. Instead of moving the text from the row to the footer textboxes and deleting the row I instead used the EditCommandColumn to create a link button like so
<asp:EditCommandColumn ButtonType="LinkButton" ItemStyle-ForeColor="Blue" EditText='[edit]' UpdateText='[update]' CancelText='[cancel]'></asp:EditCommandColumn>
I also had to add EditItemTemplate to each column, with a textbox in each, and bind the data to the textboxes in the same way that it was bound to the labels in the ItemTemplates.
Then using the ItemCommand event handler I added some code behind to set the EditItemIndex to the row that was being edited.
Private Sub GoodsList_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgdGoods.ItemCommand
Select Case e.CommandName
Case "Edit"
dgdGoods.EditItemIndex = e.Item.ItemIndex
Case "Cancel"
dgdGoods.EditItemIndex = -1
Case "Update"
dgdGoods.EditItemIndex = -1
'Update details here
Then, at the end of this rebind the data to the datagrid. With the EditCommandColumn it will automatically change from displaying the Edit button to showing the Update and Cancel buttons on the line that is being edited.

Resources