This is a migrated thread and some comments may be shown as answers.

Finding Duplicates in RadgridView

0 Answers 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Prakash
Top achievements
Rank 1
Prakash asked on 28 Mar 2011, 02:39 PM

 

Hi Team,
  
This is my requirement.
  
I need to find the duplicates based the columncollection provided. User would provide this collection
  
   
///<summary
/// Gets/Sets Column Collection in iGrid (Added for Duplicate Rows WPF) 
/// </summary
public List<string> ColumnNameCollection 
{
get; set; 
}
  
Based on this collection i would find the column index, compare data's and i need to update image which ever row gets duplicated.
  
I have written some logic to find the duplicates with the itemsource binded by user..
  
   
private List<int> GetDuplicate() 
{
List<string> columnCollection = new List<string>(); 
columnCollection.Add("Name"); 
columnCollection.Add("StadiumCapacity"); 
columnCollection.Add("Established"); 
  
int[] columnIndex = new int[columnCollection.Count]; 
  
for (int i = 0; i < columnIndex.Length; i++) 
{
columnIndex[i] = clubsGrid.Columns.IndexOf(clubsGrid.Columns[columnCollection[i]]);
}
  
Dictionary<int, string> dictobj = new Dictionary<int, string>(); 
Dictionary<int, List<int>> duplicateDic = new Dictionary<int, List<int>>(); 
  
string strrowdatas = ""; 
  
for (int i = 0; i < (clubsGrid.Items.Count); i++) 
{
strrowdatas = ""; 
  
for (int x = 0; x < columnIndex.Count(); x++) 
{
  
GridViewRow grrow = (GridViewRow)(clubsGrid.ItemContainerGenerator.ContainerFromItem(clubsGrid.Items[i])); 
strrowdatas += ":" + ((grrow).Cells[columnIndex[x]].Content as TextBlock).Text; 
}
  
bool isExists = false
  
if (dictobj.Count > 0) 
{
  
foreach (KeyValuePair<int, string> objDic in dictobj) 
{
if (objDic.Value == strrowdatas) 
{
isExists = true; 
break; 
}
}
}
  
if (!isExists) 
{
dictobj.Add(i, strrowdatas);
}
  
foreach (KeyValuePair<int, string> obj in dictobj) 
{
  
if (i != obj.Key && obj.Value == strrowdatas) 
{
if (!duplicateDic.Keys.Contains(obj.Key)) 
{
List<int> lstRows = new List<int>(); 
lstRows.Add(obj.Key);
lstRows.Add(i);
duplicateDic.Add(obj.Key, lstRows);
}
else 
{
List<int> lstRows = duplicateDic[obj.Key]; 
lstRows.Add(i);
}
break; 
}
}
}
  
List<int> st1 = new List<int>(); 
  
foreach (KeyValuePair<int, List<int>> objTes in duplicateDic) 
{
foreach (int rowin in objTes.Value) 
{
if (!st1.Contains((rowin))) 
{
st1.Add((rowin));
}
}
return st1; 
}
  
this would return list of row index which is getting duplicated. 
  
Problem #1: I need to find the duplicates based on column collection given by user. (dynamically). so above logic is gud but im confused where i can implement this logic like rowloaded or loaded or data loaded... I tried with no succes..
  
Could u please give a solution how can i find the duplicates in radgridview dynamically.

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Prakash
Top achievements
Rank 1
Share this question
or