2014-10-16 2 views
0

초보자이고 Visual Studio 2008의 Windows CE 6에서 응용 프로그램을 개발 중입니다. 사용자 세부 정보를 포함하는 DataGrid에 일부 세부 정보 상자가 사용자 세부 정보를 편집하기위한 표 아래에 배치되어 있습니다. 이제 사용자가 데이터 표를 클릭 할 때이 텍스트 상자를 채우고 싶습니다. 나는 모든 것을 시도했으며 interent의 결과는 "datagridview"를 기반으로합니다. 필요한 것은 에서 텍스트 상자를 채우는 방법입니다. DATAGRID이 아닌 DATAGRIDVIEW !!DataGrid의 자동 완성 텍스트 상자 - C#

이것은 내가 현재 행 및 현재 셀에서 텍스트 상자-이름 편집을 채우기 때문에,이 코드가 잘못 알고

int row = dgShowData.CurrentCell.RowNumber; 
int col = dgShowData.CurrentCell.ColumnNumber; 
txtNameEdit.Text = string.Format("{0}", dgShowData[row, col]); 

을 시도하는 것이다. 현재 행의 모든 ​​텍스트 상자를 채우고 싶습니다. 누군가 나를 도와주세요! 나는 지금 깊은 문제가있다 !!!

+0

아니요 확실하지만 dgShowData.CurrentCell.Text 또는 dgShowData.CurrentCell.Value 같은 것이 있습니까 ?? – User2012384

+0

데이터 그리드를 채우는 방법을 보여주세요. – Reniuz

+0

Datagrid는 데이터베이스에서 채워집니다. SqlCeDataAdapter da = 새 SqlCeDataAdapter (cmd); DataSet ds = new DataSet(); da.Fill (ds); dgShowData.DataSource = ds.Tables [0]; – Appu

답변

0

당신이 다음 셀 값을 검색 아래의 코드를 시도 할 경우 윈폼를 들어

private void dgShowData_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    DataGridRow row = GetSelectedRow(dgShowData); 
    int index = dgShowData.CurrentCell.Column.DisplayIndex; 
    DataGridCell columnCell = GetCell(dgShowData,row, index); 
    TextBlock c = (TextBlock)columnCell.Content; 
    txtNameEdit.Text = c.Text; 
} 

/// <summary> 
     /// Gets the selected row of the DataGrid 
     /// </summary> 
     /// <param name="grid">The DataGrid instance</param> 
     /// <returns></returns> 
     public static DataGridRow GetSelectedRow(this DataGrid grid) 
     { 
      return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem); 
     } 


/// <summary> 
     /// Gets the specified cell of the DataGrid 
     /// </summary> 
     /// <param name="grid">The DataGrid instance</param> 
     /// <param name="row">The row of the cell</param> 
     /// <param name="column">The column index of the cell</param> 
     /// <returns>A cell of the DataGrid</returns> 
     public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column) 
     { 
      if (row != null) 
      { 
       DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row); 

       if (presenter == null) 
       { 
        grid.ScrollIntoView(row, grid.Columns[column]); 
        presenter = GetVisualChild<DataGridCellsPresenter>(row); 
       } 

       DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); 

       return cell; 
      } 
      return null; 
     } 

편집

: 나는 지름길을 사용한

DataGridCell currentCell; 

string currentCellData; 

// Get the current cell. 

currentCell = dgShowData.CurrentCell; 

// Get the current cell's data. 

currentCellData = dgShowData[currentCell.RowNumber,currentCell.ColumnNumber].ToString(); 

// Set the TextBox's text to that of the current cell. 

txtNameEdit.Text = currentCellData; 
+0

WPF 또는 WinForms로 작업하고 있습니까 –

+0

Windows CE 응용 프로그램 만들기, Winforms – Appu

+0

WPF로 작업하고 있다고 생각했습니다 –

1

을, 희망이 도움이 될 것입니다 다른 사람도 ...

 int row = dgShowData.CurrentCell.RowNumber; 

     txtNameEdit.Text = string.Format("{0}", dgShowData[row, 0]); 
     txtNickNameEdit.Text = string.Format("{0}", dgShowData[row, 1]); 
관련 문제