How to add a row in gridview of Devexpress - devexpress

I have a form where i have some text boxes and a Gridview(with Columns in it).the values entered in textboxes should be added as a row in gridview when pressing a ADD button..below is the code in the click event of ADD button..It add as a single column not as a row..Please help me with this.
BindingList<string> Grid_data = new BindingList<string>();
Grid_data.Add(txtMaterial.Text.ToString());
Grid_data.Add(txtPlastic.Text.ToString());
Grid_data.Add(txtCoatingtype.Text.ToString());
Grid_data.Add(txtManufacturer.Text.ToString());
Grid_data.Add(txtManuDate.Text.ToString());
Grid_data.Add(txtLineSize.Text.ToString());
Grid_data.Add(txtFootage.Text.ToString());
DGMaterial.DataSource = Grid_data;
GV_Material.PopulateColumns();

To begin with, when you write : Grid_data.Add(someString) it adds a new element to the binding list not to the row. You have to understand that each element of the BindingList represents a row, not a value for a cell.
What you should do is the following :
BindingList<List<string>> gridData = new BindingList<List<string>>();
gridData.add(new List<string>() {"someString", "anotherString"}); // Your inputs here
DGMaterial.DataSource = gridData ;
GV_Material.PopulateColumns();
Hope that helps !

Related

How to add after selected row in tableview?

I have selected row, and I need to add some data right below it. Row is selected with OrderTable selectedOrderTable = orderTableId.getSelectionModel().getSelectedItem(); and new one is added with data.add(new OrderTable( ... )) It's adding OK to table, just at bottom of it, and I need to add it right below selected row selectedOrderTable.
Just call the add method taking an index:
int index = orderTableId.getSelectionModel().getSelectedIndex();
data.add(index + 1, new OrderTable(...));

Java equals string and object from ObservableList

I have a big problem. My code:
TablePosition pos = (TablePosition)
tableView.getSelectionModel().getSelectedCells().get(0);
Object item = tableView.getItems().get(pos.getRow());
Object e = ((List<ObservableList>) item).get(0);
String new_status = "textExample";
and how can I use equals ? new_status.equals(e) ? I don't have any idea on how to convert this.
p.s. in console e = "textExample".
I need this to update a sql row.
If you want to get selected items, you can just use getSelectedItems() (or getSelectedItem() if you only want the latest selection). You don't need to work with selected cells, table positions and rows.
Assuming a TableView<ObservableList<String>> (which you may or may not have). Code to retrieve the value of the first element of the selected row (probably the value represented in the first column), would be as follows:
final String NEW_STATUS = "textExample";
final TableView<ObservableList<String>> tableView = new TableView<>();
final ObservableList<String> selectedItem =
tableView.getSelectionModel().getSelectedItem();
if (selectedItem != null
&& !selectedItem.isEmpty()
&& NEW_STATUS.equals(selectedItem.get(0))) {
// do work here.
}
As your type definitions may be different you may need to adapt the code above to fit your situation as required. If you still can't work it out, you will need to edit the question to provide an mcve to get further assistance.

how to select a row in a kendogrid using a string as parameter

I need help about select a row in a kendoGrid.
I have a simple kendoGrid with selection enabled, and when i click on a button in a webpage, i have to use a string (for example "cod001") for selecting a row in my kendogrid by a column....
for example:
var grid = $("#grid").data("kendoGrid");
grid.select("??????????");//here i sould select a row where the unique value is "cod001" in a defined column
hope someone can help me.
thanks in advance.
I find an alternative solution, without each functions...
i'll post my solution, and hope can help somoeone with my same issues!!!
var g = $("#grid").data("kendoGrid");
var selectedRow = g.select();
var index = selectedRow.index();
... and then...
var ddl = $("#grid").data("kendoGrid");
ddl.select("tr:eq(" + index + ")");
you can make a loop on each line of your grid to check what the column your looking for is and then select it.
var linesToSelect = [];
$.each($('.k-grid-content tbody').children(), function(index, line){
// column is the column's value you want to test
if ($("#grid").data("kendoGrid").dataItem(line).column == "cod001")
linesToSelect.push(line);
});
$("#grid").data("kendoGrid").select(linesToSelect);
This is not a perfect solution since you do a loop on every rows of your grid, but it should help until you find a better solution!

ASP.NET add multiple series to chart via treeview selection

My page has a chart that is set up to display data that is coming from a SqlDataSource.
There is a TreeView which contains a list of datapoints that I want to be able to add to the chart as different series. The user selects which item they wish to add by clicking a checkbox in the treeview for that node and then clicks an update button to refresh the chart.
Each node's value is set to a column name in the table.
If there is only one point selected on the treeview the data comes across as a series on the chart with no problem when the update button is clicked.
If multiple items in the treeview are selected an ASP.NET error page appears when clicking the button stating that a column name 'XXXX' was not found where 'XXXX' is the node.Value of the highest item in the tree that was checked.
For example an error saying that "Column with name 'X1' was not found" would show up when using the following selection:
If just 'X1' is checked the data shows up on the chart.
public void UpdateChart(Object sender, EventArgs e)
{
if (TagTreeView.CheckedNodes.Count > 0)
{
foreach (TreeNode node in TagTreeView.CheckedNodes)
{
// Add a series to the chart
Series series = new Series();
series=Chart1.Series.Add("Series"+node.Value);
series.ChartArea = "ChartArea1";
series.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), charts[1], true);
// create a datasource, add it to the page,
SqlDataSource sqlDataSource = new SqlDataSource();
sqlDataSource.ID = "SQLDataSource"+node.Value;
sqlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["HistoricalDataConnectionString"].ConnectionString;
if (node.Depth > 1)
{
if (node.Parent.Text.Contains("AAA"))
{
MessageBox.Show(node.Value);
sqlDataSource.SelectCommand = "SELECT (Date + CONVERT(datetime,Time)) As TimeStamp, " + node.Value + " FROM AAA ORDER BY TimeStamp";
}
this.Page.Controls.Add(sqlDataSource);
Chart1.DataSourceID = "SQLDataSource"+node.Value;
Chart1.Series["Series" + node.Value].XValueMember = "TimeStamp";
Chart1.Series["Series" + node.Value].YValueMembers = node.Value;
Chart1.DataBind();
}
}
}
}
Is there a way to take each selected item in the TreeView and use the node.value to build a query to add an additional series to the chart? I have done a little bit of work to see if putting the SqlDatasource and Series objects into an array and looping through that but it doesn't seem to be taking me anywhere.
To get this to work correctly all of the datapoints that will be added to the chart need to be included in the select statement for the sqlDataSource:
sqlDataSource.SelectCommand = "SELECT (Date + CONVERT(datetime,Time)) As TimeStamp, X1, X2, X3 FROM AAA ORDER BY TimeStamp";

Is swapping the columns and rows of a flex datagrid possible?

I have a 1 row, many column flex datagrid. I would like to turn the dataGrid on its side, so that the column headers become a single column running down and v.v.
Is there a way to do that in the DataGrid?
Or am I stuck manipulating the data presented to the grid? If so whats your recommendation?
The main idea here is I have an object like:
x=y
b=u
o=p
u=e
w=p
And I'd like a control that is visually similar to that. Currently the datagrid displays the object as:
x b o u w
y u p e p
Which is too horizontal for my case. Thx
I presume that you want to convert your columns in to a single column
this can be done by getting all the columns and put the in array as provide it as a dataprovider.
DataGrid.columns
will return the columns.
and you can do some think like this to create columns.
public function createColumns():Array{
var advancedDataGridColumn:AdvancedDataGridColumn;
var i:int;
var columnsArray:Array = new Array();
for(i=0;i<columns.length;i++){
advancedDataGridColumn=new AdvancedDataGridColumn();
advancedDataGridColumn.headerText=columns[i].dispheader.toString();
advancedDataGridColumn.dataField="#"+columns[i].name.toString();
advancedDataGridColumn.itemRenderer=new ClassFactory(Styler);
if(columns[i].descending!=undefined ){
if(columns[i].descending.toString()=="true")
sortField = new SortField("#"+columns[i].name.toString(),false,true,null);
else
sortField = new SortField("#"+columns[i].name.toString(),false,false,null);
}
if(advancedDataGridColumn.headerText == Constants.price||
advancedDataGridColumn.headerText == Constants.quantity||
advancedDataGridColumn.headerText == Constants.askPrice||
advancedDataGridColumn.headerText == Constants.bidPrice||
advancedDataGridColumn.headerText == Constants.netAmount||
advancedDataGridColumn.headerText == Constants.interestAmount||
advancedDataGridColumn.headerText == Constants.principalAmount||
advancedDataGridColumn.headerText == Constants.accruedInterestAmount){
var currencyFormattor:CurrencyFormatter = new CurrencyFormatter();
currencyFormattor.useThousandsSeparator=true;
currencyFormattor.currencySymbol="";
currencyFormattor.thousandsSeparatorFrom=",";
currencyFormattor.thousandsSeparatorTo=",";
advancedDataGridColumn.formatter=currencyFormattor;
}
columnsArray.push(advancedDataGridColumn);
}
return columnsArray;
}
sorry i just copied the code but i think it will help you.
Set the DataGrid to have only 2 columns and transform the original dataset to an array collection of {propName, propValue}.
Say you have:
var originalDataSet : ArrayCollection;
var dataSet : ArrayCollection;
var columnSet : ArrayCollection;
Once you have the original values, you'll do something like:
dataSet = new ArrayCollection();
for (var i : int; i < originalDataSet.length; i++)
{
dataSet.addItem({name : columnSet.getItemAt(i), value : originalDataSet.getItemAt(i)});
}
myDataGrid.dataProvider = dataSet;//set the data provider of the grid to the transformed data set.
To clarify:
{name : columnSet.getItemAt(i), value : originalDataSet.getItemAt(i)}
This creates a new instance of type Object and assigns the name and value dynamic properties to their respective values. Instead of this you might want to define your own class with bindable properties. Note that the property names are just for this example because I don't know what you're working with actually.
The data grid at that point should have two columns defined by you, with their dataField properties set accordingly. Also, this example assumes columnSet collection contains the "horizontal columns" that you want displayed vertically. If you can obtain these based on the values in the originalDataset, you might not even need columnSet.

Resources