I am using a Editable GridView. On clicking edit button of a row, the row is coming in Editable mode and once I update the details of a current row, the row is getting saved and comes in normal mode.
Here I face one issue. When I make row to a Editable mode, On click of a button (which is not a part of grid) I want to bring Editable row mode to a normal mode.
Change the gridview's EditIndex value to -1.
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.EditIndex = -1;
}
You can put this in your "RowCancelingEdit" event
My Gridview name is grdViewDetails.
protected void grdViewDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grdViewDetails.EditIndex = -1;
grdViewDetails.DataSource = YourDatasource; //a dataset in my case
//Bind data to the GridView control.
grdViewDetails.DataBind();
}
Related
Is it possible to disable entire row selection when a cell clicked ?
i want to select row only if a checkbox column checked.
You could clear the selection this way:
private void DataGrid_SelectionChanged(Object sender, EventArgs e)
{
DataGrid.ClearSelection();
}
My Question is about to disable and Enable focused cell of Grid View and change disable cell to color on Key press
but i don't have any idea how to do that I Have done specific row Enabled False using row state helper class But now i want to disable cell How can i do that?
You can use GridView's ShowingEditor event:
private void gridViewTest_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView gridView = sender as GridView;
if(gridView.FocusedColumn.FieldName == "Product Name") // && <PUT OTHER CONDITIONS HERE>
e.Cancel = true;
}
I have grid view, and I have already disable the column auto width so I can manually set the size of column. after manually resize there's a extra blank column. and what I want is :
To disable the select row function when i click on outside of the column in Active, code and generate
Remove the extra column.
I already success fully hide the remaining column with this event or code
private void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column == null)
{
e.Handled = true;
}
}
The thing is I still can click on the outside of the genre, and the row selection still follow where I click
Handle the GridView.MouseDown event in the following way:
private void gridView1_MouseDown(object sender, MouseEventArgs e) {
GridView view = (GridView)sender;
var hi = view.CalcHitInfo(e.Location);
Console.WriteLine(hi.HitTest);
if (hi.InRow && !hi.InRowCell)
DXMouseEventArgs.GetMouseArgs(e).Handled = true;
}
Suppose if I say I have selected a row in gridview and want that row to come up in to their respective textboxes. For example, I have selected a row which has First Name and Last Names and on selection of row, the data from gridview should come in to textbox on winform. Please tell me.
I am guess it is something based on selection changed event if I am right ? Like below:
private void dgv_SelectionChanged(object sender, EventArgs e)
{
string str = txtFirstName.Text;
DataGridViewRow selectedRow;
}
If I got your question right, your solution is to use DataGridView.SelectedRows Property along with DataGridView.SelectionChanged Event
DataGridView.SelectedRows Gets the collection of rows selected by the
user.
DataGridView.SelectionChanged occurs whenever cells are selected or
the selection is canceled, whether programmatically or by user action.
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
foreach (DataGridViewRow row in dataGridView1.SelectedRows) {
//Send the first cell value into textbox'
Txt_FirstName.Text = row.Cells(0).Value.ToString; // or row.Cells["ColumnName"].Value;
}
}
}
MSDN and MSDN
I have a dynamically templated gridview.
It allows editing, deleting, and inserting new data into the table.
I also implement another function that will to allow filtering the gridview.
Currently I can do the filtering very well. However, when entering the editing mode, the gridview is somehow reset to "state before filtered".
Ex: Gridview orginally has 100 rows. After filtered only 10 rows. Enter editing mode than it will display 100 rows again.
Here is the snippet while my gridview enter the editing mode.
public void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
((TemplateField)GridView.Columns[1]).EditItemTemplate = null;
GridView.DataBind();
Session["SelecetedRowIndex"] = e.NewEditIndex;
}
Any help is appreciated...
Remove the call to DataBind() in your RowEditing method.
public void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
((TemplateField)GridView.Columns[1]).EditItemTemplate = null;
Session["SelecetedRowIndex"] = e.NewEditIndex;
}
By calling DataBind() here you're reverting the grid to its original data source, thereby losing the filtering you've previously applied.
EDIT
Have you tried re-applying your filter before your RowEditing method ends?