DataGridViewBand.Tag 속성

정의

밴드에 연결할 데이터가 포함된 개체를 가져오거나 설정합니다.

public:
 property System::Object ^ Tag { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Browsable(false)]
public object Tag { get; set; }
[System.ComponentModel.Browsable(false)]
public object? Tag { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Tag : obj with get, set
Public Property Tag As Object

속성 값

Object

밴드에 연결된 정보가 포함된 Object입니다. 기본값은 null입니다.

특성

예제

다음 코드 예제에서는 속성을 사용 하 여 Tag 나중에 속성을 설정 하기 위해 검색 되는 색을 BackColor 저장 합니다.

void PostRowCreation()
{
   SetBandColor( dataGridView->Columns[ 0 ], Color::CadetBlue );
   SetBandColor( dataGridView->Rows[ 1 ], Color::Coral );
   SetBandColor( dataGridView->Columns[ 2 ], Color::DodgerBlue );
}

void SetBandColor( DataGridViewBand^ band, Color color )
{
   band->Tag = color;
}


// Color the bands by the value stored in their tag.
void Button9_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   IEnumerator^ myEnum1 = dataGridView->Columns->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      DataGridViewBand^ band = static_cast<DataGridViewBand^>(myEnum1->Current);
      if ( band->Tag != nullptr )
      {
         band->DefaultCellStyle->BackColor =  *dynamic_cast<Color^>(band->Tag);
      }
   }

   IEnumerator^ myEnum2 = safe_cast<IEnumerable^>(dataGridView->Rows)->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      DataGridViewBand^ band = safe_cast<DataGridViewBand^>(myEnum2->Current);
      if ( band->Tag != nullptr )
      {
         band->DefaultCellStyle->BackColor =  *dynamic_cast<Color^>(band->Tag);
      }
   }
}
private void PostRowCreation()
{
    SetBandColor(dataGridView.Columns[0], Color.CadetBlue);
    SetBandColor(dataGridView.Rows[1], Color.Coral);
    SetBandColor(dataGridView.Columns[2], Color.DodgerBlue);
}

private static void SetBandColor(DataGridViewBand band, Color color)
{
    band.Tag = color;
}

// Color the bands by the value stored in their tag.
private void Button9_Click(object sender, System.EventArgs e)
{

    foreach (DataGridViewBand band in dataGridView.Columns)
    {
        if (band.Tag != null)
        {
            band.DefaultCellStyle.BackColor = (Color)band.Tag;
        }
    }

    foreach (DataGridViewBand band in dataGridView.Rows)
    {
        if (band.Tag != null)
        {
            band.DefaultCellStyle.BackColor = (Color)band.Tag;
        }
    }
}
Private Sub PostRowCreation()
    SetBandColor(dataGridView.Columns(0), Color.CadetBlue)
    SetBandColor(dataGridView.Rows(1), Color.Coral)
    SetBandColor(dataGridView.Columns(2), Color.DodgerBlue)
End Sub

Private Shared Sub SetBandColor(ByVal band As DataGridViewBand, _
    ByVal color As Color)
    band.Tag = color
End Sub

' Color the bands by the value stored in their tag.
Private Sub Button9_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button9.Click

    For Each band As DataGridViewBand In dataGridView.Columns
        If band.Tag IsNot Nothing Then
            band.DefaultCellStyle.BackColor = _
                CType(band.Tag, Color)
        End If
    Next

    For Each band As DataGridViewBand In dataGridView.Rows
        If band.Tag IsNot Nothing Then
            band.DefaultCellStyle.BackColor = _
                CType(band.Tag, Color)
        End If
    Next
End Sub

설명

이 속성은 Tag 밴드와 연결하려는 모든 개체를 저장할 수 있습니다. 이 속성은 일반적으로 문자열 이름, 고유 식별자(예: a Guid) 또는 데이터베이스에 있는 대역 데이터 인덱스 등의 식별 정보를 저장하는 데 사용됩니다.

적용 대상

추가 정보