bindingsource

How do i bind data source to a ComboBox?

帅比萌擦擦* 提交于 2019-12-23 04:34:40
问题 So i currently have two combo boxes. One Being Manufacture the other being model. My sql query looks like this "Select Distinct Model From sheet1 where (Manufacture =@Manufacture)" this works when i execute it and if i were to fill a datagridtable. But if i try to place this into a combobox i get System.data.d...... etc for my selections. How can i just have it show the values instead of all this. What am i doing wrong? private void ManuComboBox_SelectedIndexChanged(object sender, EventArgs e

Binding to nested property only showing first item in list

↘锁芯ラ 提交于 2019-12-22 12:38:24
问题 I am trying to bind a ListBox Control in C# Winforms in .NET 4.5 to a list of objects that have a nested property that I wish to use for a DisplayMember. It sort of works except that when I set the DisplayMember to the nested property the listbox only shows one item even though there are two items in the list that it is bound to. If I comment out the code for setting the DisplayMember the listBox shows two items. Is this a bug in the framework? I would like to avoid adding another property or

Using a non-collection object as a DataSource

你说的曾经没有我的故事 提交于 2019-12-21 06:35:08
问题 A bunch of dotnet framework components use a DataSource component. I have an object that has a number of settings that can modify the DataSource which it represents. I would like to set this object as the dropdown DataSource of a set of ComboBoxes and DataGridViewComboBoxCells. My problem comes when trying to actually hook the thing into the ComboBox. I guess that because the changes to the DataSource can happen once the DataSource has been set, I have to use one of these BindingSource things

Updating of BindingSource in WinForms does not update Datasource Collection

自作多情 提交于 2019-12-21 03:54:25
问题 I want to display a custom collection in a DataGridView in a Windows Forms app. This custom collection implements ICollection , and IEnumerable . I have set up a BindingSource , using the collection as the .DataSource property. The DataGridView is set to use my BindingSource as it's DataSource. When I add a new item to the collection using the BindingSource.Add() method, the DataGridView updates correctly with the new item. The BindingSource DataSource, on the other hand, does not:

How to reset bindingsource filter to nothing

ぃ、小莉子 提交于 2019-12-20 04:13:16
问题 Using BindingSource on LINQ to SQL, and having implemented a BindingList in my project, I have to use a Textbox to filter rows in a DataGridView , so when I delete the textbox content, Filter should be reset to nothing. My code is as follows: if (textBox1.Text.Length == 0) { productBindingSource.Filter = null; } else { productBindingSource.Filter = "ProductName = '" + textBox1.Text +"'"; //productBindingSource.RemoveFilter(); } productDataGridView.DataSource = productBindingSource; But this

Why do I need to change the Binding Source Position before I can SaveChanges

天涯浪子 提交于 2019-12-19 16:52:48
问题 I have a small demo WinForms app. One of the Forms is my Add New Person form. I used the Details View instead of the DataGridView from my Data Sources. When I enter data and click the save button on the Navigator there are zero changes, However I put a MovePrevious and a MoveNext after my AddNew in the form Load , everything works as expected. public partial class AddPersonForm : Form { private readonly DemoContext _context; public AddPersonForm() { _context = new DemoContext();

Why Browsable attribute makes property not bindable?

此生再无相见时 提交于 2019-12-18 17:01:08
问题 I'm trying to use System.Windows.Forms.PropertyGrid . To make a property not visible in this grid one should use BrowsableAttribute set to false . But adding this attribute makes the property not bindable. Example: Create a new Windows Forms project, and drop a TextBox and PropertyGrid onto Form1 . Using the code below, the width of the TextBox does not get bound to Data.Width : public partial class Form1 : Form { public Form1() { InitializeComponent(); Data data = new Data(); data.Text =

How to cast bindingdatasource to datatable?

半世苍凉 提交于 2019-12-17 21:23:36
问题 I'm trying to cast the bindingdatasource to datatable using this code BindingSource bs = (BindingSource)gvSideMember.DataSource; DataTable tCxC = (DataTable)bs.DataSource; throws error unable to cast bindingsource to datatable then i tried this code private DataTable GetDataTableFromDGV(DataGridView dgv) { var dt = ((DataTable)dgv.DataSource).Copy(); foreach (DataGridViewColumn column in dgv.Columns) { if (!column.Visible) { dt.Columns.Remove(column.Name); } } return dt; } it again show me

DataGridView AllowUserToAddRow property doesn't work

别来无恙 提交于 2019-12-17 16:39:42
问题 I have a simple project with Entity Framework, I have a DataGridView in my Form and I set its AllowUserToAddRow property to true but still I can not add new rows into it. And here is my code: DBEntities context = new DBEntities(); private void Form1_Load(object sender, EventArgs e) { var q = (from i in context.myTable select i).ToList(); DataGridView.DataSource = q; } private void btnSave_Click(object sender, EventArgs e) { context.SaveChanges(); MessageBox.Show("saved successfully"); } If I

How to properly commit bindingSource changes to source DB?

孤街浪徒 提交于 2019-12-13 13:38:23
问题 I setup DataGridView and other UI components to allow user to edit data from SQLite DB. But these changes (even they are properly shows in application) doesn't saves to DB. I have tried this code aBindingSource.EndEdit(); dbDataSetA.GetChanges(); aTableAdapter.Update(dbDataSetA.Accounts); but there are concurrency exception: System.Data.DBConcurrencyException was unhandled Message=Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. So how should I commit