RowCount
Row count of matrix
//Duplicate check dynamic code (Boyum IT / tbm)
Item i = form.Items.Item("38"); // Set form item
Matrix m = (Matrix)i.Specific; // Access Matrix
int rowCount = m.VisualRowCount; // Get line count
string sValue = ""; // Return string
// Create a list of all item numbers
string[] itemCodes = new string[rowCount];
// Put all itemcodes in an array
int rowrun = 1;
for (int runs = 0; runs < rowCount; runs++)
{
itemCodes[runs] = ((SAPbouiCOM.EditText)m.Columns.Item("1").Cells.Item(rowrun).Specific).Value;
rowrun++;
}
//Create LINQ dictionary from all the duplicates
System.Collections.Generic.Dictionary<string, int> counts = itemCodes.GroupBy(x => x)
.ToDictionary(g => g.Key,
g => g.Count());
//Create return string
foreach (var kvp in counts)
{
//Check if Key is empty
if (kvp.Key != "") {
//Check if itemcode only appears once
if (kvp.Value > 1) {
//Add the item code + row + occurances to the return string
sValue += string.Format("Duplicate item {0} found on row "+ (Array.IndexOf(itemCodes, kvp.Key)+ 1) +" - Duplicate amount: {1} <NEWLINE>", kvp.Key, kvp.Value);
}
}
}
//Return message based on sValue length
if (sValue.Length == 0) {
return "";
}
else {
return sValue;
}
0
System.Core.dll;
System.Linq;