Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid column value 1

Status
Not open for further replies.

eys

Programmer
Mar 5, 2001
28
MX
how can i get the datagrid column value when i select a specific row.

lets say that i have a datagrid full with employees , and i select the row where's cris Rock data, and i want the employee id wich is actually on one datagrid column.

maybe i want to edit that data or delete it from the datagrid, or go directly to a delete statement or update passing that prinary key ( value) and perform that action...

im using c# with windows forms
thanks

Jose Carlos
 
Use HitTestInfo object to retrive the row/column numbers .
private System.Windows.Forms.DataGrid.HitTestInfo m_HitTestInfo;
//
private void m_DataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
m_HitTestInfo=m_DataGrid.HitTest(e.X,e.Y);
if ( m_HitTestInfo.Type==System.Windows.Forms.DataGrid.HitTestType.Cell)
{
// you click on a cell
}
if ( m_HitTestInfo.Type==System.Windows.Forms.DataGrid.HitTestType.RowHeader)
{
// you click on a row haeder
}
int vRow = m_HitTestInfo.Row; // row clicked
int vColumn = m_HitTestInfo.Column ; // column clicked
object vCell = m_DataGrid[vRow,vColumn]; // the object stored in that cell
// if ID is the 3rd column in the row then
object id = m_DataGrid[vRow,2];

}
obislavu
 
hi mr obislavu.
thanks for your post...
but actully i solved this thing inother way, maybe end up the same solution as yours,lets look!

//****** init

string ID = null; // id to put on prim key value

BindingManagerBase bm = this.grdLista.BindingContext[this.grdLista.DataSource, grdLista.DataMember];
System.Data.DataRow dr = ((System.Data.DataRowView)bm.Current).Row;
ID =dr[0].ToString(); // putting in cell value to variable ( id)

EysAsiste.EditPuestos frmEditPuestos = new EditPuestos(ID); // passing id to new form and edit things up
frmEditPuestos.ShowDialog();

//******* end


hope this thing work for some one else... later
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top