I'm facing issue in binding single row to the treelist. In my application I have a two forms. first form contains treelist it will contain list of rows.
I need a selected row from the list. Using
public object selectedRow
{
return treelist.GetDataRecordByNode(treelist.FocusedNode)
}
using this code I get the selected row.
In second Form, I'm trying to bind that row.
public void row(selectedRow)
{
treelist2.DataSource=selectedRow; //I get the row value here.
}
But data not able to shown in second treelist. what step I need to do to bind a selectedrow to second treelist.
the DataSource should be an IEnumerable-type.
try something like this (pseudo-code ahead):
public void row(selectedRow)
{
List<yourType> list = new List<yourType>();
list.Add(selectedRow);
treelist2.DataSource=list;
}
Please go through TreeList's Data Binding section, Data Binding topic provides the complete information on binding the TreeList to data.
You can find reference to bind it with class objects here -
Binding Controls to Data Created at Runtime
In your row method, you should either create a List<ClassType> or BindingList<ClassType> before assigning the data source property. A list of ClassType objects can be created and bound to a data-aware control as follows:
BindingList<ClassType> list = new BindingList<ClassType>();
treelist2.DataSource = list;
References:
DevExpress TreeList not displaying child nodes and displaying as root nodes instead
binding data to the treelist control
Binding data in DevExpress Treelist from database
Related
I created one XtraGrid and added some values with the help of LookUpEdit and some TextBoxes.
I want to modify the values what I have added into grid here.
I am using getfocusedrowcellvalue to get values from grid into TextBoxes.
How can I get that getfocusedrowcellvalue to LookUpEdit?
example:-
txtdrmk.Text = Convert.ToString(gridView3.GetFocusedRowCellValue("remark"));//to get value from selected cell to text box.
cmbper // this is my lookupedit.
If you fire a FocusedRowChanged event, you can certainly do what you seek by using the GetFocusedRow() method against the grid view:
object o = grdCommentsView.GetFocusedRow();
From here, if your data source is a domain object, you can just cast it to that object type:
Customer c = o as Customer;
Or, if the datasource is a datatable:
DataRow dr = o as DataRow;
All that said, there is a much better way, in my opinion. Use a binding source component, bind your data (object collection or DataTable) to the binding source DataSource property, then make the binding source the data source for both the grid and any non-grid controls you have. You can access these via the (DataBindings) property.
The best part about this approach is that the data binding is codeless*, and as you change rows on the grid the values in the controls will automatically update. If you change the property value either place (control or grid), the other will reflect the update.
If you use the DataLayoutControl, it will even do the data binding for you.
I'm developing my first WPF application that queries a database and shows some records of some tables in TabControl if one or more fields of these records not satisfy certain condition.
I have a DataTable as data source and I use a DataGrid to show results (i.e. the wrong records). I'd like to use ToolTip on DataGridCell to indicate why a field is considered wrong. There's a way to iterate over the DataGridRow and the DataGridCell so that I can set dynamic ToolTipfor every specific field?
Thanks in advance.
I would bind the DataGrid selected item to a SelectedRecord property in my view model (where the data source is coming from), see Get selected row item in DataGrid WPF as an example. The SelectedRecord property would then set the SelectedRecordToolTip property in accordance to the SelectedRecord value (i.e. using a dictionary with the error as the key and the tooltip as the value). Finally, you can then bind your tooltip to the SelectedRecordToolTip property.
In my application I want to add combobox to DataGridView.
I use this code:
By DataGridView column collection property add combobox column
Use in .cs code as below
datagridview1.autogeneratedcolumn = false;
datagridview.datasource = datatable;
It show combobox in DataGridView but it did not dropdown. Means it doesn't have items (I check for datatable.. it contains all items)
In one of my apps, I bind an enum as a datasource to my combo box column. Here is the code I use to bind it (in the load event).
if (dgv.Columns[COL_INDEX] is DataGridViewComboBoxColumn)
{
((DataGridViewComboBoxColumn)dgv.Columns[COL_INDEX]).DataSource = Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>();
}
As for the row data, I use a binding source.
You can set a binding source to an object by selecting the datagridview, go to properties (F4), DataSource, Add Project Data Source, Object, select your object. The columns will be created and you can change the desired column to DataGridViewComboBoxColumn, and the above code will set your choices.
After you define your datasource you have to bind the data to the gridview
add this line after your second line
datagridview.DataBind();
Your control names are different too. Try this
datagridview1.AutoGeneratedColumn = false;
datagridview1.DataSource = datatable;
datagridview1.DataBind();
I have a method that I call in a form that returns a List and then I throw that into a BindingSource and throw the BindingSource into a DataGridView. The Order class has a property called Items that contains a List. My Order and Item class both implement the INotifyPropertyChanged Interface.
What I'm trying to do is that when a row is clicked in the DataGridView it pulls up the list of items associated with the order from it's Items property into another grid. I want to ensure that those items are 2 way binded to the grid but I can't call it the way I'd like to...
itemsGrid.DataSource = orderBindingSource[orderGrid.CurrentRow.Index].Items;
I can't access the properties of the list from within the BindingSource (After the . operator, Items is not an available option)... Any recommendations? I've tried using a BindingList<Order> and BindingList<List<Order>> but was getting implicit conversion errors. Any suggestions?
*EDIT: Ok I've managed to get the BindingList to work. I didn't know I had to add the list like this
orderList = new BindingList<Order>(Method To Retrieve List<Order>)
Aside from this, the first grid displaying the orders works and updates perfectly. The sub grid which contains the Order's Items bound like
itemsGrid.Datasource = orderList[ordersGrid.CurrentRow.Index].Items;
It displays properly. I don't have editing enabled as I have a few textboxes that are setup and each textbox is bound to the Item from the orderList of the currently selected row of the ordersGrid. I can update the data in the textboxes for the selected item in the subgrid but the changes when I leave the textbox, the sub grid's row for that item property edited does not update as I leave the textbox. It will, however, update if I select another item in the grid. How can I get it to update as I leave the textbox instead of having to click on another row in the grid?
I'm developing a web page witch has an AspxTreelist and an ASPxGridView. I would like to fill the grid with data after selecting some nodes on treelist. The treelist nodes are filtering the grid data
Here is my code samples :
Here I'm getting the selected nodes
Categories = new List<int>();
foreach (TreeListNode node in categs)
{
Categories.Add(int.Parse(node["Key"].ToString()));
}
And here I'm filling the grid
if (Categories!= null && Categories.Count > 0)
{
DGEmails.DataSource = Manager.GetBySubTree(Categories);
DGEmails.DataBind();
}
The problem is that after I get the Categories and fill the Grid's datasource (these parts work fine) there are not any data displaying on the grid.
I figured out the problem, it was the fact that treelist by default uses callbacks and I had to disable them.