Hi,
With the codes below, I'd like to populate another drop-down button, say on the top right by executing
"SELECT DISTINCT \"Delivery Month\" FROM Futures WHERE Name=Selected Market name from the center dropdown ORDER BY \"Delivery Month\"". I appreciate if you could please help me with a code snippet achieving this.
Country.cs:
namespace SyncfusionWpfDropdownTest
{
public class Country
{
public string? Name { get; set; }
}
}
Market.cs:
namespace SyncfusionWpfDropdownTest
{
public class Market
{
public string? Name { get; set; }
}
}
ViewModel.cs:
using System.Collections.ObjectModel;
using Npgsql;
namespace SyncfusionWpfDropdownTest
{
public class ViewModel
{
public ObservableCollection<Country> Countries { get; set; }
public ObservableCollection<Market> Markets { get; set; }
public ViewModel()
{
Countries = new ObservableCollection<Country>();
Markets = new ObservableCollection<Market>();
LoadData();
}
private void LoadData()
{
NpgsqlConnection conn = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
conn.Open();
string query = "SELECT DISTINCT Country FROM EconomicCalendar ORDER BY Country";
NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
NpgsqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Countries.Add(new Country
{
Name = reader.GetString(0)
});
}
NpgsqlConnection conn1 = new NpgsqlConnection("Host=192.168.1.2; Port=5432; Database=tradingapp; Username=vorlket; Password=Vcsokr.");
conn1.Open();
string query1 = "SELECT DISTINCT Name FROM Futures ORDER BY Name";
NpgsqlCommand cmd1 = new NpgsqlCommand(query1, conn1);
NpgsqlDataReader reader1 = cmd1.ExecuteReader();
while (reader1.Read())
{
Markets.Add(new Market
{
Name = reader1.GetString(0)
});
}
}
}
}
MainWindow.xaml:
<Window x:Class="SyncfusionWpfDropdownTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SyncfusionWpfDropdownTest" xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<syncfusion:DropDownButtonAdv IconHeight="1" IconWidth="1" SizeMode="Normal" x:Name="CountryButton" Label="Country">
<syncfusion:DropDownMenuGroup ScrollBarVisibility="Visible" ItemsSource="{Binding Countries}">
<syncfusion:DropDownMenuGroup.ItemTemplate>
<DataTemplate>
<syncfusion:DropDownMenuItem Header="{Binding Name}" HorizontalAlignment="Left">
</syncfusion:DropDownMenuItem>
</DataTemplate>
</syncfusion:DropDownMenuGroup.ItemTemplate>
</syncfusion:DropDownMenuGroup>
</syncfusion:DropDownButtonAdv>
</StackPanel>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Top">
<syncfusion:DropDownButtonAdv IconHeight="1" IconWidth="1" SizeMode="Normal" x:Name="MarketButton" Label="Market">
<syncfusion:DropDownMenuGroup ScrollBarVisibility="Visible" ItemsSource="{Binding Markets}">
<syncfusion:DropDownMenuGroup.ItemTemplate>
<DataTemplate>
<syncfusion:DropDownMenuItem Header="{Binding Name}" HorizontalAlignment="Left">
</syncfusion:DropDownMenuItem>
</DataTemplate>
</syncfusion:DropDownMenuGroup.ItemTemplate>
</syncfusion:DropDownMenuGroup>
</syncfusion:DropDownButtonAdv>
</StackPanel>
</Grid>
</Window>
MainWindow.xaml.cs:
using System.Windows;
namespace SyncfusionWpfDropdownTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Hi Syncfusion team,
Just a reminder for help as this might have fallen off the radar.
Thanks.
Hi Kook Jin Noh,
We have checked your query and prepared a sample to meet the requirement as a workaround solution. Please find the sample below.
If we misunderstood the requirement, please provide an update. It will help us to provide a solution promptly.
Regards,
Priyanka Vijayasankar
Hi Priyanka,
Thanks for your time helping me. I had a look at
your codes and it doesn't seem to address my question. To begin
answering my question in a right direction, answers to the following would
help:
Hi Kook Jin Noh,
Query 1: In the DropDownMenuItem click event, set the selected header value to the DropDownButtonAdv instance's label property. Please refer to the attached screenshot in Query 2 solution.
Query 2: Create a new property in ViewModel.cs and set its value in the DropDownMenuItem click event. This value can be used in an SQL query. Please refer to the attached screenshot below,
Query 3: In the setter property, the selected value is received and used to make a query by calling the new method. Please refer to the attached screenshot below,
We have attached a modified sample related to these queries. Please refer to the attached sample for your reference. Please let us know if you need any further assistance.
Regards,
Priyanka Vijayasankar
Hi Priyanka, thanks for the help, appreciate it. Could you please help me working on these warn
Hi Kook Jin Noh,
To resolve possible null reference warnings, it is important to handle nullable values using the null-conditional (?.) and null-coalescing (??) operators. Additionally, ensure that non-nullable fields are initialized with default values where necessary. For further guidance on resolving null reference issues, please refer to the attached screenshot and visit the following link:
Regards,
Priyanka Vijayasankar