Say my grid has only 1 column ("NAME").
How can I make sure I only populate the grid with NO duplications.
I've looked at multivalue converters... validationRules.
Either way, I don't know how to display values with no duplications.
Any assistance would be GREATLY appreciated.
Thanks
Java
DataGrid.Columns>
DataGridTextColumn Header="Market">
DataGridTextColumn.Binding>
MultiBinding Converter="{StaticResource ResourceKey=myConverter}">
Binding Path="tMarketName" UpdateSourceTrigger="PropertyChanged">
Binding.ValidationRules>
local:UniqueNameValidation CurrentCollection="{StaticResource ResourceKey=ViewSource}"/>
/Binding.ValidationRules>
/Binding>
Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}, AncestorLevel=1}"/>
Binding Path="."/>
Binding Source="{StaticResource ResourceKey=MyData}"/>
/MultiBinding>
/DataGridTextColumn.Binding>
/DataGridTextColumn>
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 24, 2013, 8:02 AM EDT
You can fetch distinct name from your data source before displaying to datagrid.
Regards,
Iftikar
Stephen7 reputationPosted Jul 24, 2013, 8:09 AM EDT
thanks Iftikar... but how would I do that?
I created the current collection view like soo..
<Window.Resources>
<local:DataBindingClass x:Key="formatter"/>
<local:MyDataSource x:Key="MyData"/>
<local:UniqueNameValidation x:Key="uniqueNameValidator"/>
<CollectionViewSource x:Key="ViewSource" Source="{Binding Source={StaticResource ResourceKey=MyData}, Path=TradesClass}"/>
Window.Resources>
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 24, 2013, 8:19 AM EDT
Regards,
Iftikar
Stephen7 reputationPosted Jul 24, 2013, 8:21 AM EDT
class MyDataSource
{
string myDesktop = @"C:\Users\xxx\Desktop";
public ObservableCollection<TradesClass> TradesClass { get; set; }
public MyDataSource()
{
TradesClass =
new ObservableCollection<TradesClass>();
LoadAllData();
}
private void LoadAllData()
{
TradesClass.Clear();
string sampleXmlFile = myDesktop + "/posMain.xml";
XElement libraryXml = XElement.Load(sampleXmlFile);
var tableElements = libraryXml.Elements("Table");
foreach (XElement table in tableElements)
{
#region
retrieveValfromXML
string elementAcctNumber = table.Element("Acct_x0020_Num").Value;
string elementAcctName = table.Element("Acct_x0020_Desc").Value;
long elementQty = 0;
XElement tester = table.Element("Qty");
if (tester == null)
{
elementQty = 0;
}
else
{
string sValue = tester.Value;
elementQty = System.
Convert.ToInt64(sValue);
}
string elementMonth = "";
tester = table.Element(
"Month");
if (tester == null)
{
elementMonth =
"";
}
else
{
elementMonth = tester.Value;
}
string elementMarketName = "";
tester = table.Element(
"Market_x0020_Name");
if (tester == null)
{
elementMarketName =
"";
}
else
{
elementMarketName = tester.Value;
}
decimal elementDeltaSettle = 0;
tester = table.Element(
"Delta_x0020_Settle");
if (tester == null)
{
elementDeltaSettle = 0;
}
else
{
string sValue = tester.Value;
elementDeltaSettle = System.
Convert.ToDecimal(sValue);
}
decimal elementDeltaLive = 0;
tester = table.Element(
"Delta_x0020_Live");
if (tester == null)
{
elementDeltaLive = 0;
}
else
{
string sValue = tester.Value;
elementDeltaLive = System.
Convert.ToDecimal(sValue);
}
string elementSector = "";
tester = table.Element(
"Sector");
if (tester == null)
{
elementSector =
"";
}
else
{
elementSector = tester.Value;
}
string elementBBSymbol = "";
tester = table.Element(
"BBM_x0020_Symbol");
if (tester == null)
{
elementBBSymbol =
"";
}
else
{
elementBBSymbol = tester.Value;
}
decimal elementCrynMult = 0;
tester = table.Element(
"Crncy_x0020_Mult");
if (tester == null)
{
elementCrynMult = 0;
}
else
{
string sValue = tester.Value;
elementCrynMult = System.
Convert.ToDecimal(sValue);
}
string elementProductCode = "";
tester = table.Element(
"Product_Code");
if (tester == null)
{
elementProductCode =
"";
}
else
{
elementProductCode = tester.Value;
}
decimal elementLastPrice = 0;
tester = table.Element(
"LAST_PRICE");
if (tester == null)
{
elementLastPrice = 0;
}
else
{
string sValue = tester.Value;
elementLastPrice = System.
Convert.ToDecimal(sValue);
}
decimal elementPXClose = 0;
tester = table.Element(
"PX_CLOSE_1D");
if (tester == null)
{
elementPXClose = 0;
}
else
{
string sValue = tester.Value;
elementPXClose = System.
Convert.ToDecimal(sValue);
}
double elementPLSettle = 0;
tester = table.Element(
"Settle_x0020_PL");
if (tester == null)
{
elementPLSettle = 0;
}
else
{
string sValue = tester.Value;
elementPLSettle = System.
Convert.ToDouble(sValue);
}
double elementPLLive = 0;
tester = table.Element(
"Live_x0020_PL");
if (tester == null)
{
elementPLLive = 0;
}
else
{
string sValue = tester.Value;
elementPLLive = System.
Convert.ToDouble(sValue);
}
string elementTradeDate = "";
tester = table.Element(
"Trade_x0020_Date");
if (tester == null)
{
elementTradeDate =
"";
}
else
{
elementTradeDate = tester.Value;
}
#endregion
TradesClass.Add(
new TradesClass()
{
tAcctNum = elementAcctNumber,
tAcctDesc = elementAcctName,
tQuantity = elementQty,
tMonth = elementMonth,
tMarketName = elementMarketName,
tDeltaSettle = elementDeltaSettle,
tDeltaLive = elementDeltaLive,
tSector = elementSector,
tBBSymbol = elementBBSymbol,
tCrncyMult = elementCrynMult,
tProductCode = elementProductCode,
tLastPrice = elementLastPrice,
tPXClose = elementPXClose,
tPLSettle = elementPLSettle,
tPLLive = elementPLLive,
tTradeDate = elementTradeDate
});
}
}
}
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 24, 2013, 8:29 AM EDT
public List<TradesClass> TradesClass { get; set; }
TradesClass =new List<TradesClass>();
TradesClass =TradesClass.Distinct().ToList();Regards,
Iftikar
Stephen7 reputationPosted Jul 24, 2013, 10:15 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 24, 2013, 7:49 PM EDT
Regards,
Iftikar