Add items to combobox in an already existing datagridview comboBox column - datagridviewcombobox

I have a datagridview in my Windows form Application.
The datagridview has 3 column. First column is Combobox.
I am trying to add item to the Combo box but it is working.
Here is the code( Language C#)
foreach (int counter=0; counter<5; counter++ )
{
this.dataGridView1.Rows.Add();
DataGridViewComboBoxCell cbCell = new DataGridViewComboBoxCell();
cbCell.Items.Add("Male");
cbCell.Items.Add("Female");
dataGridView1.Rows[counter].Cells[0] = cbCell;
dataGridView1.Rows[counter].Cells[1].Value = firstname[counter];
dataGridView1.Rows[counter].Cells[2].Value = lastname[counter];
}
The grid is showing 5 rows. But first Combo box column is having no item in every combo box of those.
Please help.
Thanks.

Since the code does not show how the columns are constructed, it is difficult to tell what the problem could be, however the code is not using the DataGridViewComboBoxColum. The DataGridViewComboBoxColumn is all you need to make every row in column 0 a combo box with “Male”, “Female” choices.
The malformed foreach loop is incorrect and will not compile. I assume a for loop is what you were looking for. Following this for loop… a new row is correctly added to the grid. Then a new DataGridViewComboBoxCell is created and added the cell[0] of the current row. dataGridView1.Rows[counter].Cells[0] = cbCell;. This cell[0] is added to every new row.
This is unnecessary if the DataGridViewViewComboBoxColumn is set up properly. Adding the DataGridViewComboBoxCell is perfectly valid and basically allows you to put a combo box into any “SINGLE” cell. It works however, if used this way makes the use of the combo box itself questionable.
The loop is “adding” data to dataGridView1. As you are reading in the data, the part about “Gender” (male, female) appears to be missing so the value is not set as the other values are. Example: There is not a line like below:
dataGridView1.Rows[counter].Cells[0].Value = gender[counter];
If there was a “Gender” array that held this info, then when the code sets this value (Male, Female) in the line of code above the combo box column will automatically set the combo box selection to that value. The data will only be “one” (1) of the two values.
So assuming this is what you are looking for the code below demonstrates how to use the DataGridViewComboBoxColumn
A word of caution when reading data into a combo box cell; if the string data for the combo box column does NOT match one of the items in the combo boxes items list, the code will crash if not caught and addressed. If the value is an empty string then the combo box will set the selected value to empty.
// Sample data
string[] firstname = { "John", "Bob", "Cindy", "Mary", "Clyde" };
string[] lastname = { "Melon", "Carter", "Lawrence", "Garp", "Johnson" };
string[] gender = { "Male", "", "Female", "", "Male" };
// Create the combo box column for the datagridview
DataGridViewComboBoxColumn comboCol = new DataGridViewComboBoxColumn();
comboCol.Name = "Gender";
comboCol.HeaderText = "Gender";
comboCol.Items.Add("Male");
comboCol.Items.Add("Female");
// add the combo box column and other columns to the datagridview
dataGridView1.Columns.Add(comboCol);
dataGridView1.Columns.Add("FirstName", "First Name");
dataGridView1.Columns.Add("LastName", "Last Name");
// read in the sample data
for (int counter = 0; counter < 5; counter++ )
{
dataGridView1.Rows.Add(gender[counter], firstname[counter], lastname[counter]);
}
Hope this helps.

Related

empty cells in appending data one by one into the google sheet via api v4

When i append the list of data in a column the data appended leaves the rows equivalent to the maximum rows used in the previous column and then starts appending from the last cell. The picture would explain the problem quite well. I am using flutter and gsheets dependency to connect to the sheet. Date is the column key and data is the data being appended.
if (column != null) {
if (!column.contains(data)) {
await sheet.values.map.appendRow({date: data});
}
return true;
} else {
await sheet.values.insertColumnByKey(date, [data]);
return true;
}
Current output
Required output
You should find the last cell that contains a value in the target column and insert values starting in the cell just below that cell, instead of appending after the last row of the occupied data range in the sheet.
One way to do that is to use my appendRows_() utility function.

UI5 - how to dynamically bind data to a Select in Table, depending on another combobox?

I have a classic situation - a table with two comboboxes (or, to be exact, sap.m.Select controls) and after select in the first one, I would like to have the values in the second one updated. This is my model, basically, the first combobox should contain the list of available states and once some is selected, the second sap.m.Select control should be populated by relevant cities
{
countries: [
{ country: 'France', cities: ['Paris', 'Marseille', 'Lyon']},
{ country: 'Germany', cities: ['Berlin', 'Bonn']}
]
}
The problem is that I dont know how to do it. I am able to get the id of the updated row using something like this.
onCountryChange: function (oEvent) {
const selectedItem = oEvent.getParameter("selectedItem");
var path = selectedItem.getBindingContext().getPath();
bindComboBox(path); // this should rebind the data, but not written yet
}
I know now I should rebind the data in the correct combobox, however, I don't know how to affect only that single combobox on the correct row and how to update it. Could someone advise me how to do it? The whole table is defined in the .xml view, can I do it also with a formatter or inline expression or is this scenario too difficult for that?
Thank you
You can use the bindAggregation method (from the ManagedObject) class to rebind the combo boxes' items.
onCountryChange: function (oEvent) {
const selectedItem = oEvent.getParameter("selectedItem");
var path = selectedItem.getBindingContext().getPath();
this.byId("combo2").bindAggregation("items", {
path: path + "/cities",
template: new sap.ui.core.Item({
key: "{}",
text: "{}"
})
});
}
Note: Replacing "combo2" with the id of your 2nd combo box/select control.
Edit: To get the correct combo box (assuming you have multiple created on a table, use the ID of the first combo box (oEvent.getSource().getId()) to generate the ID of the 2nd combo box. Without knowing more of the structure of the table (and how it's created) I can't offer more.

APEX Trigger when a textfield gets updated

I am trying to create a trigger in APEX, when an custom textfield of an custom sObject gets updated with products (means, when new products get insert or existing one get deleted).
How can I compare in APEX the Trigger.Old values with the Trigger? New values of this field in order to start the Trigger.
It would look something like this:
Trigger NameOfTrigger on CustomSObject__c (after update){
/*there is already an existing list of products that get insert into the custom textfield (probably as Strings)
*/
List <String> textList = new List <String> ();
/*PseudoCode: if the textfield got updated/has changed, copy from every entry of this textfield (entry = product name as a string) and copy fieldX into another sObject
*/
if(CustomSObject.field(OldValues) != CustomSObject.field(NewValues)){
for (String product : textList){
//Trigger e.g. copy the values of a certain field of p and paste them in another sObject
}
Could somebody help me with the syntax?
You can utilize inbuilt Trigger.new and Trigger.old to get the latest and old values of any record. These lists can be used to achieve what you're looking for.
Sample example would be:
Trigger NameOfTrigger on CustomSObject__c (after update){
for(CustomSObject__c customObject : Trigger.new) {
// get old record
CustomSObject__c oldCustomObject = Trigger.oldMap.get(customObject.Id);
// compare old and new values of a particular field
if(customObject.fieldName != oldCustomObject.fieldName){
//Trigger e.g. copy the values of a certain field of p and paste them in another sObject
}
}
}
See documentation of Trigger.new & Trigger.old

link multiple models on same row of sap.m.table

This may be a basic question, but it's my first, so please be kind :-).
I have a sap.m.table with two models, one model with transaction data (trxModel) and another model that is used to display a sap.m.select list (reasonCodeModel). The table model is set to trxModel.
The selected value key from the dropdown needs to update a value (ReasonCodeID) in the trxModel when a value from the reason code list is selected.
I can retrieve the selected key in the change event as so
var selKey = evt.getParameter("selectedItem").getKey();
Is there a simple way to find the trxModel relevant model path from the table row Select list value I've just modified? Or is it possible to bind the ReasonCodeID from the trxModel to the ReasonCodeID field in the reasonCodeModel?
Just an extra piece of info, The current row is selected and is accessible
var selItem = dtlTable.getSelectedItem();
2nd question and I guess could be kind of related, is there a way of getting the table model path based on the selected item (highlighted row) of the table? And vice a versa?
More details on Select & Table binding.
var tabTemplate = new sap.m.ColumnListItem(
{
::
new sap.m.Select(
"idReasonCodeSelect",
{
enabled : false,
change : function(evt) {
oS4View.getController().changeReasonCodeSel(evt);
}
}
),
Bind the resource code Select to the Table
// bind the reason codes to the reason code model
sap.ui.getCore().byId("idReasonCodeSelect").setModel(
oReasonCodeModel);
sap.ui.getCore().byId("idReasonCodeSelect").bindAggregation("items", "/results",
new sap.ui.core.Item({
key : "{ReasCodeID}",
text : "{ReasCodeDesc}"
}));
Per Qualiture comment, how do I bind the Select key to the table model ReasonCodeID value?
I found an approach to tackle the first part of my question above
From the change function on the Select, I can find the path of the table model using the following.
var path = evt.getSource().getParent().getBindingContext().sPath;
2nd Update:
On the selectionChange event on the table, there's a couple of options to find the associated model path or model content.
// find the model path
oModelPath = selItem.getBindingContext().getPath();
// model values
oItem = oEvent.getParameter("listItem").getBindingContext().getObject();
So my only remaining issue, While I loop through the table model results (trxModel) and I want the Select List (using setSelectedKey) to reflect the ReasonCodeID value in the trxModel.

TYPO3 - Adding values to a table using powermail

I made a form so that users can register their email address for a contest. Im using a powermail form and someone told me to use dbEntry to do this, but im not sure how to do it. This is my code so far:
plugin.tx_powermail_pi1{
dbEntry{
tt_address._enable = TEXT
tt_address._enable.value = 1
tt_address.email = TEXT
tt_address.email.value = ????
}
debug.output = all
}​
Ive been told to activate _enable to enable the data insertion. But now I dont know how to access the field value of the form. I probably should use the template id, which is ###UID71###, but I have no idea how.
According to the official documentation, you can do it this way:
plugin.tx_powermail.settings.setup {
dbEntry {
# enable or disable db entry for tt_address
tt_address._enable = TEXT
tt_address._enable.value = 1
# write only if field email is not yet filled with current value
# (update: update values of existing entry)
# (none: no entry if field is filled)
# (disable: always add values don't care about existing values)
tt_address._ifUnique.email = update
# fill table "tt_address" with field "pid" with the current pid (e.g. 12)
tt_address.pid = TEXT
tt_address.pid.data = TSFE:id
# fill table "tt_address" with field "tstamp" with the current time as timestamp (like 123456789)
tt_address.tstamp = TEXT
tt_address.tstamp.data = date:U
# fill table "tt_address" with field "name" with the value from powermail {firstname}
tt_address.name = TEXT
tt_address.name.field = firstname
...
}
}
I also found an (older) forum post (in German) with examples that use data from the user session:
# table "tt_address" with field "last_name" is the value from powermail (tt_content uid 88) field uid18 (###uid18###)
tt_address.last_name = TEXT
tt_address.last_name.data = TSFE:fe_user|sesData|powermail_88|uid18