2017-03-07 3 views
0

레이블 및 텍스트 상자가 포함 된 표를 프로그래밍 방식으로 생성했습니다. 코드는 다음과 같습니다.xamarin 양식 - 표에 텍스트 상자 값 가져 오기

grid.Children.Add(new Label { Text = "ID", BackgroundColor = Color.Black, IsVisible = false, FontAttributes = FontAttributes.Bold, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }, 0, 1, 0, 1); 
grid.Children.Add(new Label { Text = "Desc", BackgroundColor = Color.Black, FontAttributes = FontAttributes.Bold, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }, 1, 2, 0, 1); 
grid.Children.Add(new Label { Text = "Qty", BackgroundColor = Color.Black, FontAttributes = FontAttributes.Bold, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }, 2, 3, 0, 1); 
grid.Children.Add(new Label { Text = "Receive Qty", BackgroundColor = Color.Black, FontAttributes = FontAttributes.Bold, TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), }, 4, 6, 0, 1); 

for (int i = 0; i < 10; i++) 
{ 
    sID = e.Result[i].ID.ToString(); 
    sQty = e.Result[i].Qty.ToString(); 
    sDesc = e.Result[i].DESC1.ToString(); 
    if(e.Result[i].ReceivedQty.ToString() == "0") 
    { 
     sReceivedQty = sQty; 
    } 
    else 
    { 
     sReceivedQty = e.Result[i].ReceivedQty.ToString(); 
    } 

    grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); 
    grid.Children.Add(new Label { Text = sID, IsVisible = false, BackgroundColor = Color.Gray, TextColor = Color.White, FontSize = 
     Device.GetNamedSize(NamedSize.Micro, typeof(Label)) }, 0, 1, i + 1, i + 2); 
    grid.Children.Add(new Label { Text = sDesc, BackgroundColor = Color.Gray, TextColor = Color.White, FontSize = 
     Device.GetNamedSize(NamedSize.Micro, typeof(Label)) }, 1 2, i + 1, i + 2); 
    grid.Children.Add(new Label { Text = sQty, BackgroundColor = Color.Gray, TextColor = Color.White, FontSize = 
     Device.GetNamedSize(NamedSize.Micro, typeof(Label)) }, 2, 3, i + 1, i + 2); 
    grid.Children.Add(new Entry { Text = sReceivedQty, TextColor = Color.White, FontSize = 10 }, 3, 4, i + 1, i + 2); 
} 

각 행의 텍스트 상자에 값을 가져 오시겠습니까? 도와주세요!

답변

1

X에서 요소를 가져 오도록 Grid을 쿼리 할 수는 없지만 Grid에서 요소를 쿼리하고 해당 위치를 요청할 수 있습니다.

//get the element at position r, c 
var view = grid.Children.FirstOrDefault(v => Grid.GetRow(v) == r && Grid.GetColumn(v) == c); 
var label = view as Label; 
if (label != null) { 
    //label.Text is the string you're looking for 
} 
+0

행 색인을 모르기 때문에 위치 r과 c를 어떻게 알 수 있습니까? 나는 또 다른 문제를 안고있다. 사용자가 입력란에 입력 한 데이터를 데이터베이스에 다시 업데이트하려고합니다. 어떻게 텍스트 상자에있는 데이터가 어떤 ID에 속해 있는지 알 수는 없습니다. ID가 동일한 행의 텍스트 상자에 속해 있는지 확인할 수있는 방법이 있습니까? –

0
int index=8; 
string y = ((Label)gridName.Children.ElementAt(index)).Text; 

이 그리드에 8보기이다 레이블의 텍스트를 가져올 것이다.

관련 문제