DataGridViewCell.FormattedValue 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
표시를 위해 형식이 지정된 셀 값을 가져옵니다.
public:
property System::Object ^ FormattedValue { System::Object ^ get(); };
[System.ComponentModel.Browsable(false)]
public object FormattedValue { get; }
[System.ComponentModel.Browsable(false)]
public object? FormattedValue { get; }
[<System.ComponentModel.Browsable(false)>]
member this.FormattedValue : obj
Public ReadOnly Property FormattedValue As Object
속성 값
형식이 지정된 셀 값이거나, 셀이 DataGridView 컨트롤에 속하지 않으면 null
입니다.
- 특성
예외
ColumnIndex가 0보다 작아 셀이 행 머리글 셀임을 나타내는 경우
형식 지정이 실패하고 DataError 컨트롤의 DataGridView 이벤트에 대한 처리기가 없거나 처리기에서 ThrowException 속성을 true
로 설정한 경우. 예외 개체는 일반적으로 FormatException 형식으로 캐스팅할 수 있습니다.
예제
다음 코드 예제를 사용 하는 방법에 설명 합니다 FormattedValue 속성입니다. 이 예제 IsCurrentCellDirty 에서 속성은 현재 셀의 내용이 편집되어 커밋되지 않은지 확인하고 셀이 수정 FormattedValue 된 경우 가 사용되는지 확인하는 데 사용됩니다. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 DataGridView.SelectionChanged 이벤트입니다.
private void UpdateLabelText()
{
int WithdrawalTotal = 0;
int DepositTotal = 0;
int SelectedCellTotal = 0;
int counter;
// Iterate through all the rows and sum up the appropriate columns.
for (counter = 0; counter < (DataGridView1.Rows.Count);
counter++)
{
if (DataGridView1.Rows[counter].Cells["Withdrawals"].Value
!= null)
{
if (DataGridView1.Rows[counter].
Cells["Withdrawals"].Value.ToString().Length != 0)
{
WithdrawalTotal += int.Parse(DataGridView1.Rows[counter].
Cells["Withdrawals"].Value.ToString());
}
}
if (DataGridView1.Rows[counter].Cells["Deposits"].Value != null)
{
if (DataGridView1.Rows[counter]
.Cells["Deposits"].Value.ToString().Length != 0)
{
DepositTotal += int.Parse(DataGridView1.Rows[counter]
.Cells["Deposits"].Value.ToString());
}
}
}
// Iterate through the SelectedCells collection and sum up the values.
for (counter = 0;
counter < (DataGridView1.SelectedCells.Count); counter++)
{
if (DataGridView1.SelectedCells[counter].FormattedValueType ==
Type.GetType("System.String"))
{
string value = null;
// If the cell contains a value that has not been commited,
// use the modified value.
if (DataGridView1.IsCurrentCellDirty == true)
{
value = DataGridView1.SelectedCells[counter]
.EditedFormattedValue.ToString();
}
else
{
value = DataGridView1.SelectedCells[counter]
.FormattedValue.ToString();
}
if (value != null)
{
// Ignore cells in the Description column.
if (DataGridView1.SelectedCells[counter].ColumnIndex !=
DataGridView1.Columns["Description"].Index)
{
if (value.Length != 0)
{
SelectedCellTotal += int.Parse(value);
}
}
}
}
}
// Set the labels to reflect the current state of the DataGridView.
Label1.Text = "Withdrawals Total: " + WithdrawalTotal.ToString();
Label2.Text = "Deposits Total: " + DepositTotal.ToString();
Label3.Text = "Selected Cells Total: " + SelectedCellTotal.ToString();
Label4.Text = "Total entries: " + DataGridView1.RowCount.ToString();
}
Private Sub UpdateLabelText()
Dim WithdrawalTotal As Integer = 0
Dim DepositTotal As Integer = 0
Dim SelectedCellTotal As Integer = 0
Dim counter As Integer
' Iterate through all the rows and sum up the appropriate columns.
For counter = 0 To (DataGridView1.Rows.Count - 1)
If Not DataGridView1.Rows(counter) _
.Cells("Withdrawals").Value Is Nothing Then
If Not DataGridView1.Rows(counter) _
.Cells("Withdrawals").Value.ToString().Length = 0 Then
WithdrawalTotal += _
Integer.Parse(DataGridView1.Rows(counter) _
.Cells("Withdrawals").Value.ToString())
End If
End If
If Not DataGridView1.Rows(counter) _
.Cells("Deposits").Value Is Nothing Then
If Not DataGridView1.Rows(counter) _
.Cells("Deposits").Value.ToString().Length = 0 Then
DepositTotal += _
Integer.Parse(DataGridView1.Rows(counter) _
.Cells("Deposits").Value.ToString())
End If
End If
Next
' Iterate through the SelectedCells collection and sum up the values.
For counter = 0 To (DataGridView1.SelectedCells.Count - 1)
If DataGridView1.SelectedCells(counter).FormattedValueType Is _
Type.GetType("System.String") Then
Dim value As String = Nothing
' If the cell contains a value that has not been commited,
' use the modified value.
If (DataGridView1.IsCurrentCellDirty = True) Then
value = DataGridView1.SelectedCells(counter) _
.EditedFormattedValue.ToString()
Else
value = DataGridView1.SelectedCells(counter) _
.FormattedValue.ToString()
End If
If value IsNot Nothing Then
' Ignore cells in the Description column.
If Not DataGridView1.SelectedCells(counter).ColumnIndex = _
DataGridView1.Columns("Description").Index Then
If Not value.Length = 0 Then
SelectedCellTotal += Integer.Parse(value)
End If
End If
End If
End If
Next
' Set the labels to reflect the current state of the DataGridView.
Label1.Text = "Withdrawals Total: " & WithdrawalTotal.ToString()
Label2.Text = "Deposits Total: " & DepositTotal.ToString()
Label3.Text = "Selected Cells Total: " & SelectedCellTotal.ToString()
Label4.Text = "Total entries: " & DataGridView1.RowCount.ToString()
End Sub
설명
속성은 Value 셀에 포함된 실제 데이터 개체인 반면 FormattedValue 은 이 개체의 서식이 지정된 표현입니다. 합니다 ValueType 및 FormattedValueType 속성 데이터 형식의 이러한 값은 각각에 해당 합니다.
이 속성의 값을 가져오면 메서드를 GetFormattedValue 호출하여 셀 값을 속성으로 표시된 형식의 동일한 표시 값으로 FormattedValueType 변환합니다. 이렇게 하면 값 변환을 DataGridView.CellFormatting 사용자 지정하기 위해 처리할 수 있는 이벤트가 발생합니다.
정상적이 지 않습니다 서식 지정 하는 경우는 DataGridView.DataError 이벤트가 발생 합니다. 이 이벤트 또는 처리기 집합에 대 한 처리기가 하는 경우는 DataGridViewDataErrorEventArgs.ThrowException 속성을 true
, 예외가 throw 됩니다.
적용 대상
추가 정보
.NET