treeview Checking if node is selected - treeview

I'm having a problem.
I'm creating a software that uses a treeview control, to select the OU, and depending of the OU you select, below is the action.
when I run the code below it gives me an error
If TreeView1.SelectedNode.Nodes.Item(0) = True Then
'..........................
End If
the error is operator = is not defined for systems.windows.forms
how do I check if a certain node is selected, I'm using vb 2012.

The TreeView class has a SelectedNode property which you can use.
TreeNode tn = TreeView1.SelectedNode;
if ( tn == null )
Console.WriteLine("No tree node selected.");

Related

Radio button validation using PL/SQL

I am new to Apex Oracle and PL/SQL, trying to validate radio input from the user
Declare
begin
if :R_button = 'NO' then
:Page_comment != NULL;
end if;
end;
There are three options available, YES, NO, and N/A. if the user selects No then it should prompt a comment. how best should i achieve this?
Here's one option.
you already have a radio button (R_BUTTON)
let's suppose that return values are
Y for "Yes"
N for "No"
A for "N/A"
create a dynamic action on the radio button
When:
Event = change
Selection type = item
Item = R_BUTTON
Client-side condition - set it so that DA fires when radio button value is N/A
Type: Item = Value
Item: R_BUTTON
Value = A
True action
Action = execute JavaScript code
Code = apex.message.showPageSuccess("N/A has been chosen");
Affected elements: type = item
item = R_BUTTON
That's all. Run the page and test how it works.
This test has been made on current apex.oracle.com version (19.2):

Column provided does not belong to this DataGridView control when calling Sort

I have a DataGridViewControl with sortable columns. After editing data for one record in a row of this control, the list of records is refreshed and the DataGridViewControl gets updated:
m_Helper.UpdateRecord( some variables );
dgvMyData.DataSource = ReloadData();
Before I do that, I save SortOrder and the column which was used for sorting:
SortOrder sortOrder = dgvMyData.SortOrder;
DataGridViewColumn sortedColumn = dgvMyData.SortedColumn;
Now after reloading data I'd like to have the same sorting on the column selected beforehand, but I always end up with the error message
Column provided does not belong to this DataGridView control
The corresponding code looks like this:
ListSortDirection listSortDirection;
if ( sortOrder == SortOrder.Ascending )
{
listSortDirection = ListSortDirection.Ascending;
}
else
{
listSortDirection = ListSortDirection.Descending;
}
dgvMyData.Sort( sortedColumn, listSortDirection );
This always causes an ArgumentException with the error message shown above - I assume this happens because reloading the data for the DataGridView also causes the DataGridViewColumn to be a different one even though its called the same and contains the same type of data. How can I implement a solution?
As assumed in my question, using the instance of sortedColumn directly doesn't work as it no longer part of the grid. I instead use the column's name like this:
if ( !string.IsNullOrWhiteSpace( sortedColumn.Name ) &&
dgvMyData.Columns[ sortedColumn.Name ] != null )
{
dgvMyData.Sort(
dgvMyData.Columns[ sortedColumn.Name ],
listSortDirection );
}

Linq - Updating all the properties but not the key one

I've an 'product' object that has to update a record in db.
Through a 'productCode' I retrieve the object to update using Linq.
Which is the most elegant way to overwrite alle the property but not the key one and then save changes?
You will need to access each property anyways, as you fetch a record manually. my recommendation for easiest, fastest and cleanest code:
code = productCode_toChange
using(Entity ent = new Entity())
{
var update = (from x in ent.Products where x.productCode == code select x).First();
update.property1 = product.property1;
update.property2 = product.property2;
// and so on for each property you change
ent.SaveChanges();
}
you could of course try:
using(Entity ent = new Entity())
{
var update = (from x in ent.Products where x.productCode == code select x).First();
update = product;
ent.SaveChanges();
}
but i can almost guarantee this will not work, as product will certainly have an id-property it will try to write to update, which will throw an exception, given the case product is the LINQ-generated type for the table-instance.
Be careful to check for type-conformity. also note, that you the SQL-Type of product code should not be text, as this type is incomparable

Get IGrouping data in Repeater ItemDataBound

I am wanting to group news articles by year in a repeater. The format would be:
2010
list of articles
2011
List of Articles
My access layer returns a flat list of news articles, specifically List. Therefore, I am grouping them and binding them to the Repeater as follows:
events = DAL.GetEvents();
var groupedNewsList = from e in events
group e by e.StoryDate.Year
into g
select new {
Year = g.Key
, Events = g
};
rptEvents.DataSource = groupedNewsList;
rptEvents.DataBind();
The problem is trying to get the List from within the ItemDataBound event. So far, I have the following:
var data = e.Item.DataItem;
System.Type type = data.GetType();
// getting the year works fine
string year = (string)type.GetProperty("Year").GetValue(data, null).ToString();
// this returns something, but I can't access any properties. I need to get
//access to the contained List<News>
var newsList = type.GetProperty("Events").GetValue(data, null);
Any ideas?
Thanks in advance!
You don't have a List<News> - you just have a grouping. If you want a List<News>, you'll need to change your query, e.g.
var groupedNewsList = from e in events
group e by e.StoryDate.Year into g
select new { Year = g.Key, Events = g.ToList() };
Note that if you're using C# 4 you could do reflection rather more easily using dynamic typing:
dynamic data = e.Item.DataItem;
string year = data.Year.ToString();
List<News> newsList = data.Events;
Alternatively, you could avoid using an anonymous type in the first place - create your own GroupedNewsList type with Year and Events properties, populate that in your query, and then cast to it in your event handler.
The "sender" object in the ItemDataBound event is the repeater -- use it to get to the data-source. If the data-source has been grouped before binding, you can compare the current value to the previous value & hide the year-field if they are equal. Like this:
MyObject item = (MyObject)item.DataItem;
Repeater repeater = (sender as Repeater);
List<MyObject> items = repeater.DataSource as List<MyObject>;
Label lblGrouping = (Label)item.FindControl("lblGrouping");
if (item.ItemIndex == 0 || item.DateField.Year != items[item.ItemIndex - 1].DateField.Year) {
lblGrouping.Text = item.DateField.Year.ToString();
}
This worked for me, as I used a table with each row being one item, and the left-most column contained the "lblGrouping" control.

linq where according to selected item?

I am new to EF and LINQ, hoping to get some answers here.
I am trying to search from list with where condition that is according to the selecteditem from a combobox.
The combobox has 15 items(all bit datatypes) but let me just narrow it down to 2 for examples sake. items are( pro bono, civil)
Now I have a list called listOfAllNeutrals (object name is Neutral with properties such as pro bono (bit) and civil(bit), and I want to filter it using the where condition according to the selected item.
so if selected item = pro bono, the linq would look like this
var result = from n in listOfAllNeutrals
where n.probono==true
select n;
but my prob is how do I tell that the n.property should be according to the selecteditem?
like this:
var result = from n in listOfAllNeutrals
where getpropertyName==true
select n;
is there a simpler way, I don't want to use If conditions if possible.
You need to use if's or switch inside the getpropertyName(Neutral objNeutral) function to Map the selected item to the property you want to evaluate and evaluate it. You need to map object => property in some way.
Try
var result = from n in listOfAllNeutrals
where (selectedItem == proBono && n.probono == true)
|| (selectedItem == civil && n.civil == true)
select n;

Resources