2012-07-04 2 views
0

거의 같은 일을하는 폼 (예 : 레이블, 단추 등)에 많은 컨트롤이있을 때 종종 한 컨트롤을 사용하여 모든 컨트롤을 처리합니다.VB에서 GridView 셀에서 가져온 웹 컨트롤 캐스팅

그러나 이벤트를 던지고 컨트롤의 속성에 액세스하는 컨트롤을 알고 싶으면 "보낸 사람"개체를 올바른 형식으로 캐스팅해야합니다. DataGridView에있는

:

내가 DataGridView에 내가 이것을 시도 의 셀에 버튼의 텍스트를하고 싶지만이 wotking 아니에요 :들 :의

Dim btnGrid As New DataGridViewButtonColumn 
     btnGrid.HeaderText = "Modifier les lieu" 
     btnGrid.Text = "Mise a jour" 
     btnGrid.UseColumnTextForButtonValue = True 
     DataGridView1.Columns.Add(btnGrid) 

Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick 
     If e.ColumnIndex = 0 Then 
      index = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value 
      Dim btn As Button = CType(sender, DataGridViewButtonColumn) 
      MsgBox(btn.Text) 
     End If 
    End Sub 
+0

문제는 무엇입니까? – Alain

+0

@Alain DataGridview의 셀에있는 버튼의 텍스트를 가져오고 싶습니다. –

답변

1
Dim button As DataGridViewButtonCell = DirectCast(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex), DataGridViewButtonCell) 
MessageBox.Show(button.Value) 
+0

tnks이게 그게 아닙니다.하지만 약간의주의는 버튼의 텍스트가 아닙니다. 우리가 사용할 값만 사용할 수 있습니다. btnGrid .UseColumnTextForButtonValue = True –

+0

@Yassineedouiri. 나는 방금 내가 쓴 것을 눈치 챘다. 감사. 내 대답을 바로 잡았어. –

관련 문제