这是我的组成,其中两种组合框列(状态和现状)都需要被根据状态在数据网格改变计数的数据网格的示例代码重复值计数在数据网格组合框的单值
<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