I have a column with a button in my radgrid, I want to be able to click the button and get the values of the row in which the button is located on. This must be done without selecting the row, I remember seeing a part of code my friend wrote in which he used ".Parent" or something similar to get the row from of the button column clicked.
When you click any button in the GridButtonColumn of a RadGrid, you can access the button's row and the row's values by doing the following:
In the RadGrid's definition, add OnItemCommand="RadGrid1_ItemCommand".
In the GridButtonColumn's definition, set its command name with something like CommandName="Test".
Now add the following to your code-behind to access whatever column you want. In my sample code below I get the value in the column "Whatever":
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Test")
{
GridDataItem item = (GridDataItem)e.Item;
string columnWhateverValue = item["Whatever"].Text;
}
}
Related
i have a gridview with devexpress my gridview contain a id ID="GriviewLV1" and i have a button in the row of the gridview to edit the record , in the event click of the button im trying give click in the button to edit but cannot get the property rows or something like that. im trying something like this but cannot do rows property because dont exist the rows property in grid view devexpress
button_Edit_click(object sender, EventArgs e)
{
foreach (GridViewRow row in GriviewLV1.Rows)
{
}
}
And for what exactly do you need row collection?
As far as I know, you can only manipulate with records (DataSource property object). Also it is possible to get selected row. Some my code examples with explanation:
private List<ImageSetMember> imageSets;
...
//assign collection as grid's DataSource.
//From now on any actions on imageSets object will be automatically reproduced
//as grid's row changes.
imageSetGridControl.DataSource = imageSets;
...
private void replaceButtonEdit_Click(object sender, System.EventArgs e)
{
//get focused row record's index at DataSource collection
int index = imageSetGridView.GetDataSourceRowIndex(imageSetGridView.FocusedRowHandle);
var selectedImage = imageSet[index].Image; //accessing to row's record
}
i have only one row in my grid, when i click on a gridrow one particular cell value is stored into textbox. I have a button, when click on button that textbox value is cleared. After i clear the textbox i click again on the same gridrow but its not sending any value to textbox.
`private void DataGrid1_Selectionchanged(object sender,SelectionChangedEventArgse)
{
var selectedRow = DataGrid1.SelectedItem;
TextBox1.Text = selectedRow.coloumnName.ToString();
}
private void btn_Click(object sender, RoutedEventArgs e)
{
TextBox1.Text = "";``
}`
Edit your button's CommandName property and set it to 'Select'
Or enable auto generate select button of the GridView.
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogenerateselectbutton(v=vs.110).aspx
The selection changed handler is not firing because you have one row. The first time works but the second time there is nothing to change to. Change the handler or add a second row
How do I get data from a specific column that the edit button was pressed on in a gridview?
The following code doesnt work:
protected void viewStoryTime_OnRowEditing(object sender, GridViewEditEventArgs e)
{
SqlDataSource10.UpdateParameters["setEditHoursParam"].DefaultValue = viewStoryTime.SelectedRow.Cells[0].Text;
}
This is because the row is not actually selected. How can I accomplish this?
e.NewEditIndex has the row index of the currently-editing row. You can use that to access the row and read the cell data as necessary.
The parameter GridViewEditEventArgs contains the row index for the current edited row from the gridview.
You should do something like this
SqlDataSource10.UpdateParameters["setEditHoursParam"].DefaultValue = MyGridView.Rows[e.NewEditIndex].Cells[0].Text;
Another way could be implement a RowCommand event where parameter GridViewCommandEventArgs carries the command name, then you should do something like this:
void MyGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="my command name")
{
//Do stuff here
}
}
I want to perform operation that On a button click event , Grid Currentrow entire data is passed to an object array
I have tried to search through following links :
DataGridView selecting a specific row and retrieving its values
Getting data from selected datagridview row and which event?
But they are talking about particular cell value
i tried to perform with code
DataRowView currentDataRowView = (DataRowView)grdGLSearch.CurrentRow.DataBoundItem;
DataRow row1 = currentDataRowView.Row;
But currentDataRowView is retrieving null
one of My Senior succesfully created a generic property GetSelectedRow()
it works like this :
var object =grdGLSearch.GetSelectedRow<T>();
and it has definition
public T GetSelectedRow<T>()
{
if (this.CurrentRowIndex == -1)
{
return default(T);
}
return (base.DataSource as BindingList<T>)[this.CurrentRowIndex];
}
But it is binded to only one Main grid , i also want to use this property to another Grids
I dont want data of a particular column , i want entire row data .. and dont want any iteration to be perform ...
Is there any single liner operation for this ?
Please suggest if I am missing any links
Since you are only showing 2 lines of code, I am really not sure exactly what is going on. First off, I get you want the entire row when you click some button. However, you never state how the current row is being selected.
In order to get the full selected row, you must have a selected cell. The MSDN documentation says this on the page for DataGridView.SelectedRow. So I am assuming that the user will click a cell, and you want the entire row. I would create a variable that will hold your selected row. Then when the user clicks the cell, automatically select the row and save it. Then when the button is clicked, just retrieve the the already saved row.
private DataGridViewRow selectedRow { get; set; }
Then have the event for when the user clicks a cell
private void grdGLSearch_CellClick(object sender, DataGridViewCellEventArgs e)
{
selectedRow = grdGLSearch.Rows[e.RowIndex];
}
Finally, the button click event
private void SubmitBtn_ItemClick(object sender, ItemClickEventArgs e)
{
// to target the specific data
var cellVal1 = selectedRow.Cells["SpecificCell1"].Value;
var cellVal2 = selectedRow.Cells["SpecificCell2"].Value;
}
How can i avoid the double click on a DropDownButton used within a DataGridView? Right now I am able to view the drop down items within the DataGridView by clicking two or more times. First time it selects the cell and second time when I click on the DropDownButton arrow, it shows the list. How can I achieve the same in a single click?
Set EditMode property of the DataGridView to EditOnEnter: link
DataGridView.EditMode - Gets or sets a value indicating how to begin editing a cell.
EditOnEnter - Editing begins when the cell receives focus.
You can achieve this by subscribing for the EditingControlShowing event of the grid and there for control of type ComboBox
ComboBox ctl = e.Control as ComboBox;
ctl.Enter -= new EventHandler(ctl_Enter);
ctl.Enter += new EventHandler(ctl_Enter);
And in the Enter event, use the property
void ctl_Enter(object sender, EventArgs e)
{
(sender as ComboBox).DroppedDown = true;
}
DroppedDown indicates as the name suggests whether the dropdown area is shown or not, so whenever the control is entered this will set it to true and display the items without the need of further clicks.
The "set EditMode property of the DataGridView to EditOnEnter" worked for me, but I found another problem: user can't delete a row by just selecting and pressing DEL key. So, a google search gave me another way to do it. Just catch the event CellEnter and check if the cell is the appropriated type to perform appropriated action like this sample code:
private void Form_OnLoad(object sender, EventArgs e){
dgvArmazem.CellEnter += new DataGridViewCellEventHandler(dgvArmazem_CellEnter);
}
void dgvArmazem_CellEnter(object sender, DataGridViewCellEventArgs e)
{
DataGridView dg = (DataGridView)sender;
if (dg.CurrentCell.EditType == typeof(DataGridViewComboBoxEditingControl))
{
SendKeys.Send("{F4}");
}
}
Now the ComboBox drops down faster and the user still delete a row by selecting a row and pressing DEL key.
That's it.