i am trying to get the Gridview selected column index from wpf program. i can get the selected row index but not the selected colum index
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string lbl_nam = (Label)GridView1.Rows[GridView1.SelectedIndex].FindControl("Label_nam");
string nam = lbl_nam.Text;
}
If you are in a position to change GridView
control to DataGrid
, you can try the code given below to get the current column's display index of the DataGrid
from code behind:
dataGrid.CurrentColumn.DisplayIndex
This CurrentColumn.DisplayIndex
property of DataGrid basically gets or sets the display order of the column relative to the currently displayed columns. It provides you the zero-based position of the column as it is displayed in the associated DataGridView, or -1 if the band is not contained within a control.
Hope the information will be helpful for you ..
Regards
Debasis
This is how we can get the value of a specific cell
Object obj = GetCell(3).Content;
string cellContent = String.Empty;
if (obj != null)
{
if (obj is TextBox)
cellContent = ((TextBox)(obj)).Text;
else
cellContent = ((TextBlock)(obj)).Text;
}
private DataGridCell GetCell(int column)
{
DataGridRow rowContainer = GetRow();
if (rowContainer != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
// Try to get the cell but it may possibly be virtualized.
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
if (cell == null)
{
// Now try to bring into view and retreive the cell.
customDataGrid.UCdataGridView.ScrollIntoView(rowContainer, customDataGrid.UCdataGridView.Columns[column]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
}
return cell;
}
return null;
}
i hope it will helps you....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.