2012-06-15 81 views
0

好吧我問的東西不是傳統的。我需要創建視圖,其中有usersdays of week。如果我需要每個用戶/每天只有一個值,我可以使用datagridview。但是我需要爲每個用戶每天有一個wage字段以及一個hour字段。截圖應該會更好。控制在單個列下可編輯多個字段?

enter image description here

我需要兩個值可編輯。這裏要走什麼樣的控制方式? datagridview單元格是否可以託管兩個控件?這是這樣的要求;我還沒有決定使用Winforms或WPF,但前者是我習慣的(現在沒有太多時間研究WPF,但我只知道)。

有幾個解決方法,有一個字段,在dgv中說wage,並在dgv等外部的單獨文本框中顯示hour。但這不適用於我們的客戶端。 (我不介意任何哈克/古怪的解決方案/解決方法,這一點)

回答

1

你應該有一個標準Grid你的頭區域,那麼「行」可能是一個ItemsControl其中ItemsTemplate爲每個行的網格。然後,您可以在網格上使用SharedSizeScope對齊所有列。

這裏是我的意思

<Grid Grid.IsSharedSizeScope="True"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Grid x:Name="header"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" SharedSizeGroup="col1" /> 
      <ColumnDefinition Width="Auto" SharedSizeGroup="col2" /> 
      <ColumnDefinition Width="Auto" SharedSizeGroup="col3" /> 
     </Grid.ColumnDefinitions> 
     <TextBlock FontWeight="Bold" Text="Col1" /> 
     <TextBlock FontWeight="Bold" Text="Col2" Grid.Row="1" /> 
     <TextBlock FontWeight="Bold" Text="Col3" Grid.Row="2" /> 
    </Grid> 
    <ItemsControl ItemsSource="{Binding Users}" Grid.Row="1" x:Name="rows"> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto" SharedSizeGroup="col1" /> 
         <ColumnDefinition Width="Auto" SharedSizeGroup="col2" /> 
         <ColumnDefinition Width="Auto" SharedSizeGroup="col3" /> 
        </Grid.ColumnDefinitions> 
        <TextBlock Text="{Binding Col1Data}" /> 
        <TextBlock Text="{Binding Col2Data}" Grid.Row="1" /> 
        <TextBlock Text="{Binding Col3Data}" Grid.Row="2" /> 
       </Grid> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 
</Grid> 

此方案允許你創建喜歡的UI數據網格,輕鬆定製的最終水平的例子。

+0

院長我是WPF的絕對初學者。我會在哪裏添加此代碼? – nawfal

+0

很抱歉,我不能爲您寫出整個解決方案。我的代碼演示了一種我認爲您會覺得滿意的方法,但您需要自己應用它。祝你好運:) –

+0

院長我不是要求你寫出整個解決方案。即使你這樣做,我仍然會問現在應該怎麼處理它。我只是問,我會在哪裏應用這個。無論如何謝謝你在:) – nawfal

相關問題