這是我的組成,其中兩種組合框列(狀態和現狀)都需要被根據狀態在數據網格改變計數的數據網格的示例代碼重複值計數在數據網格組合框的單值
<Window.Resources>
<staticData:StatusList x:Key="StatusList"/>
</Window.Resources>
<Grid>
<my:DataGrid x:Name="dgData" AutoGenerateColumns="False" Margin="0,-6,0,6">
<my:DataGrid.Columns>
<my:DataGridTextColumn Binding="{Binding Subject}" Header="Subject" Width="*"/>
<my:DataGridTemplateColumn Header="Status" Width="100">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Status}"/>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Height="22"
ItemsSource="{StaticResource StatusList}"
SelectedItem="{Binding Status}"/>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
<my:DataGridTextColumn Binding="{Binding RaisedBy}" Header="Raised By" Width="100"/>
<my:DataGridTemplateColumn Header="PresentStatus" Width="100">
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Height="22"
ItemsSource="{StaticResource StatusList}"
SelectedItem="{Binding Status}"/>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
</Grid>`
C#代碼
public class StatusList : List<string>
{
public StatusList()
{
this.Add("Assigned");
this.Add("Closed");
this.Add("In Progress");
this.Add("Open");
this.Add("Resolved");
}
}
所以最後我需要保存我需要計數狀態數據網格數據時。如果狀態值(即相似值)選擇多次,則它應該作爲單一計數返回。例如,假設選擇了3個組合框,1是打開的,2是已解決的,3是打開的,則計數應爲2,因爲對於打開,當選擇多次相同的值時,它應計爲單個值(或計數)。
編輯:在這裏,我已經試過代碼的組合框狀態爲可編輯的,所以如果更改值和重複值應該算作一個值,但我不知道這一點。
bool isDuplicate;
int count;
for (int nbRow = 0; nbRow < dgData.Rows.Count; nbRow++)
{
for (int nbRowCompare = nbRow; nbRowCompare < dgData.Rows.Count; nbRowCompare++)
{
isDuplicate = true;
for (int nbCol = 0; nbCol < dgData.Rows[nbRow].Cells.Count; nbCol++)
{
if (dgData[nbCol, nbRow].Value != dgData[nbCol, nbRowCompare])
{
isDuplicate = false;
count++;
break; //Exit for each column if they are not duplicate
}
}
if (isDuplicate)
{
//Do something
count++;
}
}
}
在這裏,我試圖代碼的組合框狀態爲可編輯的,所以如果更改值和重複值應該算作一個值,但IAM的不知道它,請幫助我以這種方式
bool isDuplicate; int count; for(int nbRow = 0; nbRow < dgData.Rows.Count; nbRow++){for(int nbRowCompare = nbRow; nbRowCompare < dgData.Rows.Count; nbRowCompare++){isDuplicate = true; for(int nbCol = 0; nbCol < dgData.Rows[nbRow].Cells.Count; nbCol++) {if(dgData[nbCol, nbRow].Value != dgData[nbCol, nbRowCompare]){isDuplicate = false; count++;break; //Exit for each column if they are not duplicate }}if(isDuplicate){//Do something count++;}}}
嗨,親愛的,你的問題沒有多大意義。你能提供一個你得到什麼輸出的例子,以及你的期望輸出應該是什麼? – Rachel 2012-07-23 18:46:45
例如選擇4個組合框1row-打開2row-解決3row-閉合4row-打開 所以我需要這些選定的組合框計數如上計數應該是4但打開狀態重複,所以計數應該是3 – Honey 2012-07-23 19:19:38