Use DataColumn values as source for ValueList on UltraGridColumn - infragistics

Is there a way I can use a DataColumn from a DataTable as the ValueList for an UltraGrid column?
I have the column style set to DropDownList. The question is, what do I use for ValueList?
ultraGrid1.DisplayLayout.Bands[0].Columns["col"].Style = ColumnStyle.DropDownList;
ultraGrid1.DisplayLayout.Bands[0].Columns["col"].ValueList = ???

Create a BindableValueList. One of the Constructors takes the object for the datasource, the dataMember, the displayMember, valueMember, and bindingContextControl.
The line of code to set the ValueList:
this.ultraGrid1.DisplayLayout.Bands[0].Columns["col"].ValueList = new BindableValueList(dt, "", "displayColumn","valueColumn", this.ultraGrid1);
In the above example, dt is the DataTable you are binding to, displayColumn and valueColumn would be the keys for the columns that you want to use as the display and value portions of the drop down. If you are binding to a DataSet and want to bind to a table other than the first table you would use the second parameter to pass in the name of the table to bind to.

This could be of help. It a simple procedure that receives a DataTable, the value for the Key property of the ValueList and the name of the field to use as list for the the ValueList and returns a Value list to set in one of your UltraGridColums
public ValueList DataTableToValueList(DataTable dt, string vlKey, string fieldName)
{
ValueList vl = new ValueList();
if (!string.IsNullOrEmpty(vlKey)) vl.Key = vlKey;
foreach (DataRowView r in dt.DefaultView)
vl.ValueListItems.Add(r[fieldName]);
return vl;
}
use in this way (probably in the InitializeLayout event)
grd.DisplayLayout.Bands[0].Columns["col"].ValueList =
DataTableToValueList(dtCustomers,"vlCustomer", "CustomerName");

Related

Filling a DataGridView ComboBox with values in C/C++

I'm creating a windows forms application for university. My data is stored in multible c arrays of abstract data types. Each array is displayed in it's own datagridview. This all works no problem.
Since the data is connected like in a database I added a new column to my parent table and set the ColumnType to DataGridViewComboBoxColumn. Now I need to fill this combobox with the data of a different array / datagridview.
I've already tried to add the options manually from my array as discribed in this question: Filling DataGridView ComboBox programatically in unbound mode?. Since I need to use C/C++ and this example uses vb the used functions are not availible. I can select my column dataGridView1->Columns[0] but the ->Items does not exist.
Is it possible to create a datasource from my arrays to link them directly? Or have I overlooked a way to add them manually from my array?
You don't provide any code, neither you describe well where did you ran into a problem. Assuming you're after unbound list to be filled into the DataGridViewComboBoxColumn, here is a simple example.
C#:
DataTable dt;
dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("Category", typeof(string));
dt.Rows.Add({1, "Fruits"});
dt.Rows.Add({2, "Vegetables"});
dt.Rows.Add({3, "Trees"});
DataGridViewComboBoxColumn dgCol = this.DataGridView1.columns("Category");
dgCol.ValueMember = "ID";
dgCol.DisplayMember = "Category";
dgCol.DataSource = dt;
In this example, we create a DataTable, fill it with desired values and use it as a DataSource of the DataGridViewComboBoxColumn. Obviously, your values provided to this column in the DataGridView DataSource must match IDs in the list in new DataTable "dt".
You can convert an array or other data into DataTable or even use them directly as DataSource. It depends on what data you have. The principle will be very similar, though.
VB.NET:
Dim dt As DataTable
dt.Columns.Add("ID", GetType(Int32))
dt.Columns.Add("Category", GetType(String))
dt.Rows.Add({1, "Fruits"})
dt.Rows.Add({2, "Vegetables"})
dt.Rows.Add({3, "Trees"})
Dim dgCol As DataGridViewComboBoxColumn = Me.DataGridView1.columns("Category")
dgCol.ValueMember = "ID"
dgCol.DisplayMember = "Category"
dgCol.DataSource = dt

How to get value from listview in c++

I'm using C++ Builder 2010. I'm wondering, how can I get a value from ListView component? And is it possible get value only from 2-nd column(for instance).
I found a lot of information about adding values to ListView, not reading.
When you add a new item, the TListItems::Add() method returns a TListItem*. To access an existing item, you use the same TListItems to get a TListItem* for the desired item, eg:
// get the desired item by its index in the list...
TListItem *Item = ListView1->Items->Item[index];
In any given item, the 1st column is represented by the TListItem::Caption property, and subsequent columns are represented by the TListItem::SubItems property. So, just like when adding values using SubItems, you use SubItems to read the values, eg:
String value = item->SubItems->Strings[0]; // 0 = 2nd column, 1 = 3rd column, etc...

Python dictionary map to SQL string with list comprehension

I have a python dictionary that maps column names from a source table to a destination table.
Note: this question was answered in a previous thread for a different query string, but this query string is more complicated and I'm not sure if it can be generated using the same list comprehension method.
Dictionary:
tablemap_computer = {
'ComputerID' : 'computer_id',
'HostName' : 'host_name',
'Number' : 'number'
}
I need to dynamically produce the following query string, such that it will update properly when new column name pairs are added to the dictionary.
(ComputerID, HostName, Number) VALUES (%(computer_id.name)s, %(host_name)s, %(number)s)
I started with a list comprehension but I only was able to generate the first part of the query string so far with this technique.
queryStrInsert = '('+','.join([tm_val for tm_key, tm_val in tablemap_incident.items()])+')'
print(queryStrInsert)
#Output
#(computer_id,host_name,number)
#Still must generate the remaining part of the query string parameterized VALUES
If I understand what you're trying to get at, you can get it done this way:
holder = list(zip(*tablemap_computer.items()))
"insert into mytable ({0}) values ({1})".format(",".join(holder[0]), ",".join(["%({})s".format(x) for x in holder[1]]))
This should yield:
# 'insert into mytable (HostName,Number,ComputerID) values (%(host_name)s,%(number)s,%(computer_id)s)'
I hope this helps.

ColdFusion ValueList for dynamically named queries

I've discovered that the valuelist() function doesn't like dynamically named queries:
<cfscript>
variables.nNumber = 1;
request.qDirectories = new query();
request.qDirectories.setDBType('query');
request.qDirectories.setAttributes(qDirectories=request.qAllDirectories);
request.qDirectories.setSQL("SELECT id, name, abbr, multiproperties, isPublished,
isArchived, dateAdded, lastModified, lastModifiedBy,
prefix, lstJournalCodes FROM qDirectories");
request["qDirectories#variables.nNumber#"] = request.qDirectories.execute().getResult();
writeDump(valueList(request["qDirectories#variables.nNumber#"].id));
</cfscript>
Upon discovering this, I thought arrayToList() would help. It does help but it only brings back an array with one value in even if there are multiple rows.
Is there a way to get all the values from a particular column in a dynamically named query?
Copying/referencing the dynamic query to a simpler variable name doesn't help? As in:
tempQry= request["qDirectories#variables.nNumber#"];
valueList(tempQry.id);

list of SelectedRows in QTableWidget

I have problem getting selected rows from QTableWidget. I have table like this:
[id] [ key ]
0 test
1 pass
I want to get every row's key values. I tried QTableWidget->selectedIndexes(); but it says it's protected and I can't access that. When I tried QTableWidget->SelectionModel->selectedIndexes, I don't know how to loop through list and get the key values. Do anyone know better way how can I do it?
Regards.
I'm assuming that you set the selection behavior of your table widget to select rows.
You can always access the so-called "selection model" of any item view/widget. QTableWidget inherits from QAbstractItemView, which gives you access to this special model. This model can tell you the selected rows as a list of QModelIndex, which can then tell you the row. Once you've got them, you can access the table content, in your case the text in the column with index 1 (key column).
static const KEY_COLUMN = 1;
QList<QString> selectedKeys;
QItemSelectionModel *selectionModel = ui->tableWidget->selectionModel();
foreach(QModelIndex index, selectionModel->selectedRows())
selectedIDs << ui->tableWidget->item(index->row(), KEY_COLUMN)->text();
Because you are using QTableWidget, you probably want to be calling selectedItems(). Your results will be based on what you have set the selection behavior to, via setSelectionBehavior()
When you have a list of items, you can specifically get the second column item (if it wasn't selected already):
QTableWigetItem *keyItem = table->item(anItem->row(), 1);
QString val = keyItem->text();