Hi Team
I need help and want to improve my back end logic, when debugging its not displaying the data to the grid.
public void PopulateGrid()
{
Managers.BatchMaterialManager.SetAdriotConnection();
var dtBatchRecipe = Managers.BatchMaterialManager.GetBatcherMatAndWbMat();
DataView dv = dtBatchRecipe.DefaultView;
Managers.BatchMaterialManager.SetDefaultConnection();
/*try
{
dv.RowFilter = string.Format("CONVERT({0}, System.String) not like %PREMIX%");
View.GridMacroRecipe.ItemsSource = dv;
DataView dvPremix = dtBatchRecipe.DefaultView;
dvPremix.RowFilter = string.Format("CONVERT({0}, System.String) like %PREMIX");
}catch(Exception ex)
{
}
*/
}
//user load control
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
LoadControl();
presenter.PopulateGrid();
}
// loads data to the server
public void LoadControl()
{
Managers.BatchMaterialManager.SetAdriotConnection();
presenter.PopulateComboBox();
Properties.Settings.Default.Process = "Recipes";
string[] arrayOil = RecipeName.Split('/');
string OilIndicator = string.Empty;
if (arrayOil.Length > 1)
{
OilIndicator = arrayOil[arrayOil.Length - 2].ToString();
}
else
{
// Handle the case where there is no '/' in RecipeName
OilIndicator = ""; // Or set it to some default value or throw an exception
}
string LastDigit = string.Empty;
if (RecipeName.Length > 1)
{
LastDigit = RecipeName[RecipeName.Length - 2].ToString();
}
else
{
// Handle the case where RecipeName is too short
LastDigit = ""; // Or set it to some default value or throw an exception
}
if (OilIndicator == "2")
{
txtBagWeight.IsEnabled = false;
}
}
// front end wpf grid
Dharmeshwaran SPosted Jun 22, 2024, 7:41 AM
You should follow the below steps to correctly the show the data from any backend in WPF application. I just mocked the data to show the example
Step 1: Create the Backend Data Source
Create a simple data source in the form of a list of objects. In a real application, this could be fetched from a database or a web API.
Step 2: Create the ViewModel
The ViewModel will hold the collection of products and provide it to the view.
Step 3: Set Up the View (XAML)
Create the XAML file for your main window and bind the DataGrid to the ViewModel.
Step 4: Bind the ViewModel to the View
In the code-behind of the MainWindow, set the DataContext to an instance of the ViewModel.
Step 5: Build and Run the Application
Compile and run your application. The DataGrid should display the products defined in the ViewModel.
Note that this setup provides only a basic but complete example of displaying data in a DataGrid in WPF using a ViewModel and data binding. You need to alter the code based on your requirment