DataGrid e valori delle caselle

martedì 02 agosto 2005 - 11.54

fabcri Profilo | Newbie

Salve,
Sapete come si puo' ricavare il valore scritto in una particolare casella della datagrid ?

Cteniza Profilo | Guru

this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.DataGrid1CurrentCellChanged);
void DataGrid1CurrentCellChanged(object sender, System.EventArgs e)
{
CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid1.DataSource,dataGrid1.DataMember];
DataRowView currentRow = (DataRowView)cm.Current;
MessageBox.Show(currentRow[0].ToString());

}

Naturalmente al posto della cella 0 sei liberissimo di utilizzare qualsias cella.
Puoi anche utilizzare hittestinfo:

this.dataGrid1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.DataGrid1MouseMove);

void DataGrid1MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
DataGrid.HitTestInfo htInfo;
htInfo = dataGrid1.HitTest(e.X, e.Y);
string testo = "";
if (htInfo.Type == DataGrid.HitTestType.Cell)
testo = dataGrid1[htInfo.Row,htInfo.Column].ToString();
this.statusBar1.Text = testo;
if (htInfo.Type == DataGrid.HitTestType.ColumnResize)
this.statusBar1.Text = String.Format("Colonna Ridimensionata {0}", htInfo.Column);
}

Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5