I have a gridview as you can see here:
As you can see i read the data in materialrequestcontractorId i have a listbox that this listbox reads its value from the database as you can see here:
List<MaterialRequestContractor> lstMRC = _materialRequestContractorRepository.Get().ToList();
foreach (MaterialRequestContractor VARIABLE in lstMRC)
{
LstMaterialRequestContractorId.Items.Add(VARIABLE.Id);
}
But the problem is i need to show my user the name of my MaterialRequestContractor not its id ,the id should be the value of my name and be saved in database .but in devexpress i can't assign this value and text to list box?
I have a record in my MaterialRequestContractor database with id=1
DevExpress provides several lookup editors for WinForms (LookUpEdit, GridLookUpEdit, SearchLookUpEdit) which support such scenario out-of-the-box. The idea is that LookUp editor has its own data source. When it is shown in the grid, it finds a value with from the grid cell in its data source (the key column determined by the LookUpEdit.Properties.ValueMember property) and shows the value from a field that selected as DisplayMember.
So if you put a table that has MaterialRequestContractor and MaterialRequestContractorId fields, and properly select DisplayMember and ValueMember, the DevExpress grid should work just like you described.
Related
I have developed a small application but ran into this problem, so I'm starting with a clean slate to try and isolate it. So far, I made a very simple Windows form (VS 2017) application connecting to an SQL data table. On the form, I have a combo box for selecting a table row that is bound to the data set. I have it displaying an order number, and have its value member as an EntryID number as shown, which is also the "selected value".
I also have a simple text box on the form displaying the EntryID.
When I run the app, the combo box initially displays an ordered list of order numbers like this:
Before selecting an item, if I scroll through the list using the form's tool bar selector, the EntryID text box value corresponds to the combo box value, so Ord40 selects the last data set row (where EntryID = 1003).
When an item is selected, however, the combo box list order changes. For example, after a few selections, I get:
But if I select the last display item, "Ord 20", I still get the data row EntryID = 1003. In other words, although the bound data set does not change, the combobox scrambles the displayed item. Put yet another way, if the combobox has a set of display fields and a corresponding set of value fields, the display field text get out of sync with the underlying value.
I hope that makes sense. This is straight, out of the box, no altered code on a fresh project, and I have tried different settings on the "selected value" property.
Any help would be much appreciated.
James
You are binding SelectedValue of the ComboBox to the same data source which you use as data source of the control. Setting DataSource is just for showing items in dropdown. Setting SelecetdValue if for changing the value of bound property/column.
You never want to bind SelectedValue to the same data source which you use for DataSource.
Just as a an example, assuming you have the following tables:
Product (Id, Name, CategoryId, Price)
Category (Id, Name)
Then if you want to show a ComboBox for CategoryId in the edit form of Product, the setup of the categoryIdComboBox should be:
DataSource: categoriesDataSource
DisplayMember: Name
ValueMember: Id
SelectedValue: productsBindigSource - CategoryId
i m using C#, i am having problem in retrieving value of particular cell in gridview. the scenario is, there is a list of jobs shown in my grid. Coloumns are job_id, and job_title. I am populating my grid from database, so the grid shows a list of jobs available. and client can click on job_title, which is a hyperlink (
you can use DataKeys Property
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx
You can embedd job_id in hyperlink - hyperlink can be part of you database (one extra column) or created when you are populating your grid with data from database.
I'm trying to populate a combo box from a dataset, then bind it to a different data row.
The datarow contains a single customer records.
The dataset contains 1 table with title_id (an int) and title (the text description).
I set the value and display members, and the datasource of the combo box:
cbxTitle.ValueMember = "title_id";
cbxTitle.DisplayMember = "title";
cbxTitle.DataSource = dsTitles.Tables[0];
Next I set the data binding to the data row with the customers details:
cbxTitle.DataBindings.Add("Text", drCustomer.Table, "title_id");
When I run it, the combo box displays the number 2 (the value of title_id in the data row).
If I click it, it contains Mr, Mrs, Miss etc as i'd expect (Mr = 2)
What I can't figure out is how to get it to display 'Mr' instead of 2?!
How about:
cbxTitle.DataBindings.Add("SelectedValue", drCustomer.Table, "title_id");
Please refer to these links too:
Entity Framework 4 Databinding on WinForms ComboBoxes with Foreign Keys
Why does the ComboBox.SelectedValue DataBinding context gets cleared when BindingList changes?
I am trying to bind a numeric field in an oracle table to a Datagridview - combo list in windows forms. With this what am trying to achieve is;
1 ) Based on the numeric value present in the number field, fetch ad display the respective string value in dataviewgridcombolist column.
2). When a new row is added in the datagrid view, the user may be allowed to select a listed (string) value in the combo list and the respective index value to be stored in the table back.
lots of thanks in advance..
Regards
Rithesh Krishnan
I've created a customized grid control. Where you can specify each column type the respective editing control will be displayed - for the combo box column a combo box field will be displayed, for the numeric column a numeric editor will be displayed.
While user adding a new row also user will get these editors. Usage of this class as follows
customDataGrid1.ColumnDataTypeMapping.Add("EmployeeName", CustomDataGrid.CustomDataGridColumnType.TEXT);
customDataGrid1.ColumnDataTypeMapping.Add("ManagerID", CustomDataGrid.CustomDataGridColumnType.COMBOBOX);
customDataGrid1.ColumnDataTypeMapping.Add("JoinDate", CustomDataGrid.CustomDataGridColumnType.DATE);
customDataGrid1.ColumnDataTypeMapping.Add("DateOfBirth", CustomDataGrid.CustomDataGridColumnType.DATETIME);
customDataGrid1.ColumnDataTypeMapping.Add("Salary", CustomDataGrid.CustomDataGridColumnType.NUMERIC);
I have created a Windows form using Visual C# - this contains a rich textbox. I have an Access database containing text in 2 cells (rows) of 1 column.
What I want to be able to do is:
Concatenate the contents of rows within my Access table
Display the concatenated rows in the rich textbox on my form
Be able to edit the contents of the rich textbox and save the changes back to the table
So far I have bound the table to the rich textbox, though only 1 cell (row) is being displayed - the data that I will be concatenating is text, each cell in the table won't have a unique value - each cell simply holds a section of a paragraph.
I have read the Update command & Retrieve command of ADO.Net, though it seems that data must have a specific value i.e. Select Name from People where value = Peter
Is there a chance of me achieving what I want to achieve here?
No.
Instead, I would store each value in a separate column in the database, and then bind each textbox to that field.