DevExpress VerticalGrid set value of cell that has no fieldname - devexpress

In the DevExpress VerticalGrid InitNewRecord event, I am able to set the cell value when the row has a value in the fieldname property:
string zipcode = "99999";
VGrid.SetCellValue(VGrid.GetRowByFieldName("zipcode"), e.RecordIndex, zipcode);
However, for rows with no value in their fieldname property, I am unable to do so. This is not working:
string city = "unknown";
VGrid.SetCellValue(VGrid.Rows["rowcity"], e.RecordIndex, city);
The row's (Name) property contains the value rowcity. I'm trying to get the row by its name.
I have also tried
string city = "unknown";
VGrid.SetCellValue(rowcity, e.RecordIndex, city);
where I'm trying to get the row using the member that has been automatically created.
I've also tried casting rowcity to BaseRow:
string city = "unknown";
DevExpress.XtraVerticalGrid.Rows.BaseRow mybaserow;
mybaserow = (DevExpress.XtraVerticalGrid.Rows.BaseRow) rowcity;
VGrid.SetCellValue(mybaserow, e.RecordIndex, city);
Have also tried via Properties:
VGrid.SetCellValue( rowcity.Properties, e.RecordIndex, "unknown");
but no joy.
What am I overlooking?

The CustomUnboundData event is how to accomplish this.
EDIT: In a rush, sorry...
The event fires as many times as there are unbound fields.
In the eventhandler, you examine the eventargs fieldname property (in a switch statment) and set the value of the fieldname(s) you want to set.

Related

How do i get value of DataBinder.Eval in RowCommand without using cell index or DataKey

I want the values without using cells as they might change later and the values i want are not primary key so i cant put them in datakeys so how can i get values in RowCommand event
I am getting Null value for this
strRequestMedium = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "RequestMedium"));
I tried to use row which was already getting me values from labels
for ex:
GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
strRequiredByDate = Convert.ToString(((Label)row.FindControl("lblRequiredDateTime")).Text);
But this was also not working as it is not allowed or something

Alternative for recursive expressions in DataColumn

In my DataSet (which is persisted as XML), I have an Area table with three columns: ID, Name, and ParentId. ParentId is a foreign key that refers back to ID, effectively creating a hierarchy of Areas.
I want to maintain the full path of each Area in a new column called Path, whose value can be defined recursively as
{ area.Name ; if ParentId is null
area.Path := {
{ Parent.Path + "\" + area.Name ; otherwise
I would have liked to implement this column as a computed column.
Unfortunately, when I try to set the Expression property to the following expression
iif(isnull(ParentId, 0) = 0, Name, Parent.Path + '\' + Name)
I get the following error:
Cannot set Expression property due to circular reference in the expression.
This seems to rule out a computed column. So what are the alternatives? I.e. how can I make sure that the Path column always contain a correct value that can be used in a data-bound UI?
Attach an event handler to the datatable's row adding/changing (use events ending in ING as these fire before) events and check the value being added/altered has a closed path

How to return unique index value of multiple items selected in listbox

I have a listbox in VB.NET that allows users to select multiple categories. I need to put these categories into a database and need the index value from the listbox of the categories as the database works off IDs. SelectedItems (with an s) does not work in the net application.
I have tried the following code:
For Each category As ListItem In CategoryListBox.Items
If category.Selected Then
Dim courseCategory As New CourseCategory
courseCategory.CourseID = course.ID
courseCategory.CategoryID = CategoryListBox.SelectedIndex
Using courseCategoryEntities As New Eng_NWDTrainingWebsiteEntities
courseCategoryEntities.CourseCategories.Add(courseCategory)
courseCategoryEntities.SaveChanges()
End Using
End If
Next
When iterating through the loop the code that is:
courseCategory.CategoryID = CategoryListBox.SelectedIndex
works correctly the first time around.
On the second iteration of the loop, it goes to the next selected item however returns the index for the first selected value. How do I return the values of the other indexes selected?
It depends on what ID you need to pass to your database. If it is truly the index of the ListItem in the ListBox, then you would use:
courseCategory.CategoryID = CategoryListBox.Items.IndexOf(category);
That may not be the best approach however. Maybe the order of the ListItems changes, messing up your indexes. You probably want to store the actual CategoryID on each ListItem. The Value property works well for that. You set the column you want as the DataValueField like so:
<asp:ListBox ID="CategoryListBox" runat="server"
DataValueField="CategoryID "></asp:ListBox>
So as you are looping through each ListItem in the ListBox and checking if it is selected, just use it's Value property.
For Each category As ListItem In CategoryListBox.Items
If category.Selected Then
Dim courseCategory As New CourseCategory
courseCategory.CourseID = course.ID
courseCategory.CategoryID = category.Value;
Using courseCategoryEntities As New Eng_NWDTrainingWebsiteEntities
courseCategoryEntities.CourseCategories.Add(courseCategory)
courseCategoryEntities.SaveChanges()
End Using
End If
Next
Fixed the code by deselecting the item in the listbox after it was successfully saved.
End Using
category.Selected = False
End If
This solved my problem.

How would I populate a DropDownList's value and text fields with information in a DataTable?

How would I populate a DropDownList's value and text fields with information in a DataTable?
Example DataTable
Employees : EmployeeID, Name
I tried...
EmployeeDropDownList.DataTextField = Employees.NameColumn
EmployeeDropDownList.DataValueField = Employees.EmployeeIDColumn
EmployeeDropDownList.DataBind()
The two assignment lines are invalid though because it's not the correct datatype.
EmployeeDropDownList.DataSource=Employees.DefaultView
EmployeeDropDownList.DataTextField = "Name"
EmployeeDropDownList.DataValueField = "EmployeeID"
EmployeeDropDownList.DataBind()
Try this
EmployeeDropDownList.DataTextField = "NameColumn"
EmployeeDropDownList.DataValueField = "EmployeeIDColumn"
Did you try
EmployeeDropDownList.DataTextField = "NameColumn"
EmployeeDropDownList.DataValueField = "EmployeeIDColumn"
The DataTextField and DataValueField accept string values only. Whereas, in your code you had given DataColumn type as those property's values.

Column Value of multiselect rows in jqgrid

Its like I have multiselect option in Jqgrid in which i want to pass the selected rows value to the server and based on the value i will delete the rows. I dont want to have the ids to do my work. For the Single row i get the cell value and delete using the same. But for multi select its not the case. In getGridParam('selarrrow'); I use this to fetch the selected rows bu the values are not getting populated. Please help me out in doing the same
When i use the following code as i saw in some sample question i can fetch the value for the single row selection but when i select multiple rows then i pass it says like "FALSE" or "UNDEFINED". What can be the issue. var grid = jQuery('#list'); var sel_id = grid.jqGrid('getGridParam', 'selarrrow'); var myCellData = grid.jqGrid('getCell', sel_id, 'CountryId');
I got this done by using the for loop for getting the selected rows id
i did some thing like this and I am able to fetch the value. Thought this might help others too please check it
var myrow;
var id = jQuery("#List").jqGrid('getGridParam','selarrrow');
if(id.length)
{
for (var i=0;i<id.length;i++) // For Multiple Delete of row
{
myrow = jQuery("#List").jqGrid('getCell',id[i],'ticker');
}
}

Resources