I have devexpress gridcontrol which looks like that:
I have click event on this red X button:
private void delete_button_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
}
How can get there row index where this button is ?
You cannot access rows on GridControl, since this is just a container for the views.
As I can see from your picture you're using GridView. When you press the delete button, focused row changes and you can access it via FocusedRowHandle.
private void delete_button_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
var gv = myGridControl.MainView as GridView;
var index = gv.FocusedRowHandle;
gv.DeleteRow(index);
}
You can use the GridView.FocusedRowHandle property:
view.DeleteRow(view.FocusedRowHandle);
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 am a newbie to devexpress, I really need help on how to manage NavBarControl item. When Navbar item onclick event is fired I want to load a GridView into gridControl.
For example. Let say I have two item/link in Group A which are link 1 and link 2, when Group A - Link 1 is clicked I want to load gridview1 into gridControl1 and if Link 2 is clicked load gridView2 to gridControl
How can I achieve this?
When Navbar item onclick event is fired I want to load a GridView into gridControl.
Take a look at the NavBarControl.LinkClicked event. You can handle this event as follows(use the e.Link property to detect the specific link):
navBarControl1.LinkClicked += navBarControl1_LinkClicked;
//...
void navBarControl1_LinkClicked(object sender, NavBarLinkEventArgs e) {
if(e.Link.Item == navBarItem1)
gridControl1.MainView = gridView1;
if(e.Link.Item == navBarItem2)
gridControl1.MainView = cardView1;
}
Or you can handle the corresponding NavBarItem.LinkClicked event for the specific items:
navBarItem1.LinkClicked += navBarItem1_LinkClicked;
navBarItem2.LinkClicked += navBarItem2_LinkClicked;
//...
void navBarItem1_LinkClicked(object sender, NavBarLinkEventArgs e) {
gridControl1.MainView = gridView1;
}
void navBarItem2_LinkClicked(object sender, NavBarLinkEventArgs e) {
gridControl1.MainView = cardView1;
}
I have two image buttons in the GridView used for selection. They populate the textboxes. What I need is when i click imagebutton "Edit" it should populate the textboxes from the gridview and when the imagebutton "Delete" is pressed it does the same and disbale the textboxes too. The point is am not getting a logic of how to get the column indexes programmatically.
help me out with the condition.
the issue is just with the c# code. Here is the snippet which i have tried:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
var row = GridView1.SelectedRow;
if (condition)
{
_PropertyTitle.Text = row.Cells[1].Text;
_Address.Text = row.Cells[2].Text;
}
else
{
_PropertyTitle.Text = row.Cells[1].Text;
_PropertyTitle.Enabled = false;
_Address.Text = row.Cells[2].Text;
_Address.Enabled = false;
}
}
}
It is not very clear from question that what you are trying to achieve.But what i got is you want to write specify both image button click separately.
for that you have to use the RowCommand event.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
In this row command event according to CommandName (of button) you can manage the code for two buttons
Refer this link for Rowcommand event row command
One more link
I have tried this but its not working,giving null value:please tell me what have to change in this code.
protected void Button1_Click(object sender, EventArgs e)
{
GridViewRow row;
row = dgData.Rows[0];
DropDownList ddl= (DropDownList)(row.Cells[1].FindControl("ddlCol1"));
}
use
DropDownList ddl= (DropDownList)(row.FindControl("ddlCol1"));
and try and let me know
try this code on click event
foreach (GridViewRow row in GridView1.Rows)
{
//Finding Dropdown control
DropDownList ddl1 = row.FindControl("ddlTest") as DropDownList;
if (ddl1 != null)
{
// your code here
}
}
#creby i saw your code.
you are adding your dropdown in grid view during row data bound event ok.. but now when you click on the button, all the drop down will be vanished so that's why you will not able to get drop down.
use item template of grid view and then bind dropdown in row data bound event.
Here is code that i used to access dropdownlist inside gridview on button click.I know its due to postback of page.But how to fix it.
protected void Button1_Click(object sender, EventArgs e)
{
GridViewRow row;
row = dgData.Rows[0];
DropDownList ddl= (DropDownList)(row.Cells[1].FindControl("ddlCol1"));
}
On page load i have called the method to bind gridview.
if (page.ispostback==false)
{
grdbind();
}
try with 0th cell if it is first
(row.Cells[0].FindControl("ddlCol1"))