BindingManagerBase.Current Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Ketika ditimpa di kelas turunan, mendapatkan objek saat ini.
public:
abstract property System::Object ^ Current { System::Object ^ get(); };
public abstract object Current { get; }
public abstract object? Current { get; }
member this.Current : obj
Public MustOverride ReadOnly Property Current As Object
Nilai Properti
Yang Object mewakili objek saat ini.
Contoh
Contoh kode berikut mencetak nilai Current objek dalam peristiwa BindingManagerBaseCurrentChanged . Contoh mengasumsikan sumber data berisi DataTable yang DataColumn bernama CustName
.
void Current_Changed( Object^ sender, EventArgs^ /*e*/ )
{
BindingManagerBase^ bm = dynamic_cast<BindingManagerBase^>(sender);
/* Check the type of the Current object. If it is not a
DataRowView, exit the method. */
if ( bm->Current->GetType() != DataRowView::typeid )
return;
// Otherwise, print the value of the column named "CustName".
DataRowView^ drv = dynamic_cast<DataRowView^>(bm->Current);
Console::Write( "CurrentChanged): " );
Console::Write( drv[ "CustName" ] );
Console::WriteLine();
}
private void Current_Changed(object sender, EventArgs e)
{
BindingManagerBase bm = (BindingManagerBase) sender;
/* Check the type of the Current object. If it is not a
DataRowView, exit the method. */
if(bm.Current.GetType() != typeof(DataRowView)) return;
// Otherwise, print the value of the column named "CustName".
DataRowView drv = (DataRowView) bm.Current;
Console.Write("CurrentChanged): ");
Console.Write(drv["CustName"]);
Console.WriteLine();
}
Private Sub Current_Changed(sender As Object, e As EventArgs)
Dim bm As BindingManagerBase = CType(sender, BindingManagerBase)
' Check the type of the Current object. If it is not a
' DataRowView, exit the method.
If bm.Current.GetType() IsNot GetType(DataRowView) Then
Return
End If
' Otherwise, print the value of the column named "CustName".
Dim drv As DataRowView = CType(bm.Current, DataRowView)
Console.Write("CurrentChanged): ")
Console.Write(drv("CustName"))
Console.WriteLine()
End Sub
Keterangan
Objek Current berisi nilai item saat ini di sumber data. Untuk menggunakan nilai item saat ini, Anda harus mentransmisikan item ke Type objek yang dimuat oleh DataSource. Misalnya, berisi DataTableDataRowView objek. Untuk menentukan jenis objek saat ini, gunakan GetType metode dan ToString .
Catatan
DataSource Ketika adalah DataSet, , DataViewManageratau DataTable, Anda benar-benar mengikat ke DataView. Akibatnya, setiap Current objek adalah DataRowView objek .