We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

ArrayList Duplication Removal

private class RangeList : IComparable { public int row, col; public RangeList(int row, int col) { this.row = row; this.col = col; } #region IComparable Members public int CompareTo(object obj) { RangeList temp = (RangeList)obj; if(this.row > temp.row) return 1; if(this.row < temp.row) return -1; if(this.row == temp.row) { if(this.col > temp.col) return -1; if(this.col < temp.col) return 1; else return 0; } return 0; } #endregion }; --------- private ArrayList GetParsedRangeList(GridRangeInfoList rangeInfoList) { ArrayList splitArray = new ArrayList(); ArrayList arrList = new ArrayList(); String delimiterStr = ";"; char[] delimiter = delimiterStr.ToCharArray(); string[] rowDataArray = rangeInfoList.Info.Split( delimiter ); //Filter out the duplicate records in Arraylist. for(int i = 0; i< rowDataArray.Length ; i++) { if(!splitArray.Contains(rowDataArray[i].Trim())) { splitArray.Add(rowDataArray[i].Trim()); } } if(splitArray.Count==0) { return null; } IEnumerator iEnumList = splitArray.GetEnumerator(); while(iEnumList.MoveNext() ) { string strParsedString = Regex.Replace(iEnumList.Current.ToString(),";",""); string[] strArray; ArrayList newListArr = new ArrayList(); //Matches the '':'' for finding ranges if(Regex.Match(strParsedString,":").Success) { strArray = Regex.Split(strParsedString,":",RegexOptions.None); Match matchRowColStart = Regex.Match(strArray[0],@"[\d]+"); Match matchRowColEnd = Regex.Match(strArray[1],@"[\d]+"); int rowOneCnt = int.Parse(matchRowColStart.Value); int rowTwoCnt = int.Parse(matchRowColEnd.Value); int colOneCnt =int.Parse(matchRowColStart.NextMatch().Value); int colTwoCnt =int.Parse(matchRowColEnd.NextMatch().Value); for(int i= rowOneCnt; i<=rowTwoCnt;i++) { for(int j =colOneCnt; j<=colTwoCnt; j++) { arrList.Add(new RangeList(i,j)); } } } else { Match matchRange = Regex.Match(strParsedString,@"[\d]+"); int rowRange = int.Parse(matchRange.Value); int colRange = int.Parse(matchRange.NextMatch().Value); arrList.Add(new RangeList(rowRange,colRange)); } } return arrList; } Say for example the range selection done is like below R1C1:R1C2;R1C1:R1C3;R1C3; In this see arrList.Add(new RangeList(i,j)); will add all the range value selected while copying to a notepad.So,duplicate values are copied again like R1C1:R1C2; copies range first then R1C1:R1C3 copies range secondly and R1C3 copies thirdly. so all the values are copied to arraylist. So give me any solution to overcome this situation asap.

4 Replies

AD Administrator Syncfusion Team April 20, 2006 02:59 PM UTC

Hi Vijay, Before adding the cell info into the array list just check whether the list contains the cell already and then add it. Please find the modified code below. private ArrayList GetParsedRangeList(GridRangeInfoList rangeInfoList) { ArrayList splitArray = new ArrayList(); ArrayList arrList = new ArrayList(); String delimiterStr = ";"; char[] delimiter = delimiterStr.ToCharArray(); string[] rowDataArray = rangeInfoList.Info.Split( delimiter ); //Filter out the duplicate records in Arraylist. for(int i = 0; i< rowDataArray.Length ; i++) { if(!splitArray.Contains(rowDataArray[i].Trim())) { splitArray.Add(rowDataArray[i].Trim()); } } if(splitArray.Count==0) { return null; } IEnumerator iEnumList = splitArray.GetEnumerator(); while(iEnumList.MoveNext() ) { string strParsedString = Regex.Replace(iEnumList.Current.ToString(),";",""); string[] strArray; ArrayList newListArr = new ArrayList(); //Matches the '''':'''' for finding ranges if(Regex.Match(strParsedString,":").Success) { strArray = Regex.Split(strParsedString,":",RegexOptions.None); Match matchRowColStart = Regex.Match(strArray[0],@"[\d]+"); Match matchRowColEnd = Regex.Match(strArray[1],@"[\d]+"); int rowOneCnt = int.Parse(matchRowColStart.Value); int rowTwoCnt = int.Parse(matchRowColEnd.Value); int colOneCnt =int.Parse(matchRowColStart.NextMatch().Value); int colTwoCnt =int.Parse(matchRowColEnd.NextMatch().Value); for(int i= rowOneCnt; i<=rowTwoCnt;i++) { for(int j =colOneCnt; j<=colTwoCnt; j++) { bool flg=false; foreach(RangeList rl in arrList) { if(rl.row == i && rl.col == j) { flg=true; break; } } if(!flg) arrList.Add(new RangeList(i,j)); } } } else { Match matchRange = Regex.Match(strParsedString,@"[\d]+"); int rowRange = int.Parse(matchRange.Value); int colRange = int.Parse(matchRange.NextMatch().Value); bool flg = false; foreach(RangeList rl in arrList) { if(rl.col == colRange && rl.row == rowRange) { flg=true; break; } } if(!flg) arrList.Add(new RangeList(rowRange,colRange)); } } return arrList; } Regards, Calvin.


VI Vijay April 21, 2006 08:21 AM UTC

Thanks a lot for your help. (Some performance issue are there while looping it again.) My objective was to copy cell contents into a notepad as such without any trimming of leading space. We have a code like _gridcontrol.cutPaste.CopyTextToClipboard(_gridControl.Selections.Ranges) - which actually trims the leading space value. In this while doing a copy the leading space cell values are truncated and a copy was done.Inorder to overcome this ,i wrote a function.But due to some performance issue like usage of arraylist etc in earlier code.I put a break for this approach.Is there any suggestion like can we override CopyTextToClipboard of syncfusion to acheive this functionality.Since this is a com dll,i was not able to see the exact method written.So, if we want to acheive my expected functionality how can i write a overriding code.Pls reply me asap.


AD Administrator Syncfusion Team April 24, 2006 05:45 AM UTC

Hi Vijay, Here is the implementation of CopyTextToClipboard method. You can modify and use the CopyTextToBuffer method instead of calling the CopyTextToClipboard method. Let us know if this helps. using Syncfusion.ComponentModel; public bool CopyTextToBuffer(out string buffer, GridRangeInfoList rangeList, out int nRowsDone, out int nColsDone) { // Store rows / columns indexes to process in an array. GridRangeInfoList rowRanges = rangeList.GetRowRanges(GridRangeInfoType.Cells|GridRangeInfoType.Rows); GridRangeInfoList colRanges = rangeList.GetColRanges(GridRangeInfoType.Cells|GridRangeInfoType.Cols); // Determine number of rows / cols to process. int nRows = 0; foreach (GridRangeInfo range in rowRanges) nRows += range.Height; int nCols = 0; foreach (GridRangeInfo range in colRanges) nCols += range.Width; int dwSize = nRows*nCols; nRowsDone = 0; nColsDone = 0; // Status message, let the user abort the operation. using (OperationFeedback op = new OperationFeedback(this.gridControl1.Model)) { op.AllowCancel = true; bool canceled = false; bool bAnyChar = false; string sTabDelim = "\t"; StringBuilder sb = new StringBuilder(); GridData gridData = this.gridControl1.Data; GridStyleInfo style; try { // fill pOldCellsArray row by row for (int rowindex = 0; !canceled && rowindex < rowRanges.Count; rowindex++) { for (int nRow = rowRanges[rowindex].Top; nRow <= rowRanges[rowindex].Bottom; nRow++) { if (nRowsDone > 0) sb.Append(Environment.NewLine); bool firstCol; firstCol = true; nColsDone = 0; for (int colindex = 0; !canceled && colindex < colRanges.Count; colindex++) { for (int nCol = colRanges[colindex].Left; nCol <= colRanges[colindex].Right; nCol++) { // Store styles in array, but allow user to abort int dwIndex = nRowsDone*nCols+nColsDone; if (!firstCol) sb.Append(sTabDelim); // Get text from control (and give control the chance // to convert value into unformatted text or vice versa). //string sText = GetCopyTextRowCol(nRow, nCol); style = new GridStyleInfo(gridData[nRow, nCol]); string sText = style.CellValue.ToString(); // sText = new StringBuilder(sText) // .Replace(Environment.NewLine, " ") // .Replace("\r", " ") // .Replace("", " ") // .ToString() // .Trim(); sb.Append(sText); bAnyChar |= sText.Length > 0; firstCol = false; // check, if user pressed ESC to cancel op.PercentComplete = (int) (dwIndex * 100 / dwSize); if (op.ShouldCancel) throw new GridUserCanceledException(); nColsDone++; } } nRowsDone++; } } } catch(GridUserCanceledException ex) { canceled = true; throw ex; } if (nRowsDone > 1 || nColsDone > 1) sb.Append(Environment.NewLine); buffer = sb.ToString(); return !canceled && bAnyChar; } } Regards, Calvin.


VI Vijay May 5, 2006 07:08 AM UTC

Thanks a lot Calvin.I have implemented your approach with some changes it works fine. Regards Vijay.T >Hi Vijay, > >Here is the implementation of CopyTextToClipboard method. You can modify and use the CopyTextToBuffer method instead of calling the CopyTextToClipboard method. Let us know if this helps. > >using Syncfusion.ComponentModel; > >public bool CopyTextToBuffer(out string buffer, GridRangeInfoList rangeList, out int nRowsDone, out int nColsDone) > { > // Store rows / columns indexes to process in an array. > GridRangeInfoList rowRanges = rangeList.GetRowRanges(GridRangeInfoType.Cells|GridRangeInfoType.Rows); > GridRangeInfoList colRanges = rangeList.GetColRanges(GridRangeInfoType.Cells|GridRangeInfoType.Cols); > > // Determine number of rows / cols to process. > int nRows = 0; > foreach (GridRangeInfo range in rowRanges) > nRows += range.Height; > > int nCols = 0; > foreach (GridRangeInfo range in colRanges) > nCols += range.Width; > > int dwSize = nRows*nCols; > > nRowsDone = 0; > nColsDone = 0; > > // Status message, let the user abort the operation. > using (OperationFeedback op = new OperationFeedback(this.gridControl1.Model)) > { > op.AllowCancel = true; > bool canceled = false; > bool bAnyChar = false; > > string sTabDelim = "\t"; > > StringBuilder sb = new StringBuilder(); > GridData gridData = this.gridControl1.Data; > GridStyleInfo style; > > try > { > // fill pOldCellsArray row by row > for (int rowindex = 0; !canceled && rowindex < rowRanges.Count; rowindex++) > { > for (int nRow = rowRanges[rowindex].Top; nRow <= rowRanges[rowindex].Bottom; nRow++) > { > if (nRowsDone > 0) > sb.Append(Environment.NewLine); > > bool firstCol; > firstCol = true; > nColsDone = 0; > > for (int colindex = 0; !canceled && colindex < colRanges.Count; colindex++) > { > for (int nCol = colRanges[colindex].Left; nCol <= colRanges[colindex].Right; nCol++) > { > > // Store styles in array, but allow user to abort > int dwIndex = nRowsDone*nCols+nColsDone; > > if (!firstCol) > sb.Append(sTabDelim); > > // Get text from control (and give control the chance > // to convert value into unformatted text or vice versa). > //string sText = GetCopyTextRowCol(nRow, nCol); > style = new GridStyleInfo(gridData[nRow, nCol]); > string sText = style.CellValue.ToString(); >// sText = new StringBuilder(sText) >// .Replace(Environment.NewLine, " ") >// .Replace("\r", " ") >// .Replace("", " ") >// .ToString() >// .Trim(); > > sb.Append(sText); > > bAnyChar |= sText.Length > 0; > firstCol = false; > > // check, if user pressed ESC to cancel > op.PercentComplete = (int) (dwIndex * 100 / dwSize); > if (op.ShouldCancel) > throw new GridUserCanceledException(); > > nColsDone++; > } > } > > nRowsDone++; > } > } > } > catch(GridUserCanceledException ex) > { > canceled = true; > throw ex; > } > > if (nRowsDone > 1 || nColsDone > 1) > sb.Append(Environment.NewLine); > > buffer = sb.ToString(); > > return !canceled && bAnyChar; > } > } > > >Regards, >Calvin.

Loader.
Live Chat Icon For mobile
Up arrow icon