I have a DataSet setup like the following:
As can be seen, there's a relationship between both tables.
In my form page I have the following layout:
The combobox simply select the 'platform' and what I want to get is that the ListBox only shows records that belongs to the relationship, filtered by plataforma_id.
In the TableAdaptor of the Table 'SetupUrlConditions' I have set it up like the following:
When I run the app, the ListBox always shows all records instead of being filtered by the relationship. Changing the ComboBox selected item, the result is always the same.
So, Is there something missing in my code to accomplish this?
Thanks.
EDIT:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Backoffice
{
public partial class SetupRules : Form
{
public SetupRules()
{
InitializeComponent();
}
private void plataformasBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.plataformasBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.plataformasDataSet);
}
private void SetupRules_Load(object sender, EventArgs e)
{
this.plataformasTableAdapter.Fill(this.plataformasDataSet.plataformas);
this.setupUrlConditionsTableAdapter.Fill(this.plataformasDataSet.SetupUrlConditions);
}
}
}
private void PlatformasCBO_SelectedValueChanged(object sender, EventArgs e)
{
if (PlatformasCBO.SelectedValue != null)
{
SiteUrlLstBox.DataSource = this.platformasDataSet.SetupUrlConditions.Where( p => p.platforma_id == (int)PlatformasCBO.SelectedValue).ToList();
}
}
Ok you made me dig for that one since I haven't done it in such a long time...
Combobox = Platformas. Properties to be set are DisplayMember = Plaformas, ValueMember = Id
ListBox just displaymember = condicion?... up to you from there.
Keep in mind that something is always selected with this setup it would need to be modified to have nothing selected initially but out of scope for the question
Related
I've created a windows form called Grades and when I click the Submit button, it displays the "System.Windows.Form" onto the label and then the text I've entered onto the textbox. For example, it displays "System.Windows.Form Tom". Now I've been researching online and people say that I should add it as a reference. I already did that and it seems as though that the using statement isn't greyed in like the other using statements. Please Help!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Grades
{
public partial class frmGrades : Form
{
public frmGrades()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
lblDisplayStudentName.Text = Convert.ToString(txtBoxStudentName);
lblDisplayMessage.Text = Convert.ToString(txtBoxStudentGrade);
}
}
}
You need to get the text property of the textbox :
lblDisplayStudentName.Text = txtBoxStudentName.Text;
lblDisplayMessage.Text = txtBoxStudentGrade.Text;
What I have is a project that is called from our ERP. The ERP calls functions that are exposed in the C# project and info is passed back and forth. This works great, but I am having an issue with the "Cancel" button. When the cancel button is clicked I want it to jsut close the C# form and not return anything.... Pretty much just terminate any action in C# and sever the connection to the ERP. I have tried many forms of the environment and application commands but they also close the ERP as well as the C# form. Are there any recommendations of the best approach for this? I can send the dialog from the button back to the ERP and just have the ERP not do anything with a true value but I am wondering if there isn't a more efficient way to accomplish this. Thank in advance.
Edit: Here is the current code on the form that contains the buttons. The cancel button is and has been set with DialogResult = Cancel as well...
The problem is that certain functions will be called from the ERP when this form is instantiated. Using this.close() does close the form but it also returns values back to the ERP, which I do not want it to do.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NavAutomation
{
public partial class NAVForm : Form
{
public NAVForm(string frmName, int maxLen)
{
InitializeComponent();
}
private void NAVForm_Load(object sender, EventArgs e)
{
}
public string RetVal1 { get; set; }
public string txtB1 { get; set; }
public int txtB1Len { get; set; }
private void button2_Click(object sender, EventArgs e)
{
this.RetVal1 = textBox1.Text;
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
}
}
What I ended up doing, which works great is default a bool to true, and pass back false on the cancel button/close button and then simply exited the calling code in our ERP and it works like a dream. Thanks for the comments.
I started new project of Windows Forms. First page is UserLogin. in form load event I am taking the logintable from database into memory.
I am using a class in which all read and write operations methods are stored.
when I am calling the class in formload event, the error comes "doesnot exist in current context"
I may be missing some references or headerfilename..
Please Help
Thanks in Advance
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Web;
namespace InvestmentAndReturns
{
public partial class UserLogin : Form
{
public UserLogin()
{
InitializeComponent();
CenterToScreen();
}
public string UserID = null;
private string userPass = null;
public string UserGroup = null;
DataTable UserLoginTable;
int logintry = 1;
public bool LoginStatus = false;
private void Form1_Load(object sender, EventArgs e)
{
txtUserID.Select();
string cmd = "Select * from UserLogin";
UserLoginTable = DbRdRw.SqlDbRead(cmd, "UserLogin");
}
DbRdRw: this is the Class
SqlDbRead: this is read method
i have included that class by directly pasting it in the project folder and then opened solution and then included in the project
It looks like you have copy pasted source file containing definition of DbRdRw from some other project - which mostly means the namespace declaration in the file will be from older project.
Things will work if you change the namespace to your current project InvestmentAndReturns.
However, why are you copy pasting this around? You could make a library dll for your DbRdRw and reference the dll. That way you will keep your source code at one place.
I use Entity Framework ObjectResult coming from Execute method to bind data to a WPF control, like here:
using System;
using System.Data;
using System.Data.Objects;
using System.Windows;
using System.Linq;
namespace Microsoft.Samples.Edm
{
/// <summary>
/// Interaction logic for SalesOrders.xaml
/// </summary>
public partial class SalesOrders : Window
{
private AdventureWorksEntities context;
private int customerId = 277;
private void SalesOrdersForm_Loaded(object sender, RoutedEventArgs e)
{
// Instantiate the ObjectContext.
context = new AdventureWorksEntities();
// Define a query that returns orders for a customer.
// Because lazy loading is on by default, SalesOrderDetails
// related to a SalesOrderHeader will be loaded when the query
// is executed.
var query = from o in context.SalesOrderHeaders
where o.CustomerID == customerId
select o;
// Execute the query and bind the result to the OrderItems control.
this.orderItemsGrid.DataContext = ((ObjectQuery)query).Execute(MergeOption.AppendOnly);
}
private void buttonClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
public SalesOrders()
{
InitializeComponent();
}
}
}
The example comes from MSDN
It work fine, but how do I refresh the binding? Either programmatically or when database changes?
The SalesOrdersForm_Loaded code should be seperated from this event.
Place this code in a function. and call it in form load. Now you can call this function on your requirement basis.
I hope it makes sense.
Edit
You can call this function on button click / Timer or any event based on your requirement to update the bindings
I'm using Dynamic Data and LINQ to SQL for some admin pages on a .NET 3.5 web app. All my admin tables have a CreatedBy, CreatedDate, UpdatedBy, and UpdatedDate.
I'm looking for a way to inject the setting of these properties before the objects are inserted and updated.
I've seen an object_inserting hook if you have a linq to sql datasource in the web form, but I'm using dynamic data...is there an easy way to generically set that? And I've also looked at modifying each of the partial classes for my admin objects, but the closest hook I see is to implement the OnValidate method with the Insert action. Any suggestions? TIA.
David Turvey has published a great example of adding in an OnSaving and OnSaved methods for your entities, check here: Adding OnSaving an OnSaved Events to LINQ to SQL Entities
By implementing the above on your entities, you can extend them with a partial class, e.g.
partial class MyAdminEntity : EntityBase
{
internal override OnSaving(ChangeAction changeAction)
{
if (changeAction == ChangeAction.Insert)
{
CreatedBy = "<username>";
CreatedDate = DateTime.Now;
}
else if (changeAction == ChangeAction.Update)
{
CreatedBy = "<username>";
CreatedDate = DateTime.Now;
}
}
}
I got tried, add your entity class to app_code, change the class to partial class, it works for me! Hope this help! Reference here.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Objects;
using System.Data.Linq;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace NorthwindModel
{
public partial class NorthwindEntities
{
partial void OnContextCreated()
{
// Register the handler for the SavingChanges event.
this.SavingChanges += new EventHandler(context_SavingChanges);
}
// SavingChanges event handler.
private static void context_SavingChanges(object sender, EventArgs e)
{
var objects = ((ObjectContext)sender).ObjectStateManager;
// Get new objects
foreach (ObjectStateEntry entry in objects.GetObjectStateEntries(EntityState.Added))
{
// Find an object state entry for a SalesOrderHeader object.
if (entry.Entity.GetType() == typeof(Employee))
{
var usr = entry.Entity as Employee;
// Do your Business Logic here.
}
}
}
}
}
I know this is an old post, but this could help others in solving their problem.
There are some other ways to do that.
You can use this:
public partial class BasicModelDataContext : DataContext
{
partial void InsertEmployee(Employee instance)
{
instance.MyValue = "NEW VALUE";
Employee.Insert(instance);
}
partial void UpdateEmployee(Employee instance)
{
instance.MyValue = "NEW Update VALUE";
Employee.Update(instance);
}
}