Binding list in RadGridView - wpf

I am using Telerik RadGridView to display dynamic data, stored in classes like bellow:
public class Field
{
public string FieldName{ get; set; }
public string FieldValue{ get; set; }
}
public class Row
{
public List<Field> Fields{ get; set; }
public Row()
{
Fields= new List<Field>();
}
}
A Row has "n" Fields.
I need to display each "Row" in a line in the grid and each Field like a column in the line.
When I set:
myGrid.ItemSource = myList;
I get something like this:
Fields
--------------------
(Collection)
(Collection)
...
When I really need is a table like this:
Name Gender Date ...
----------- --------- --------
JOHN M 10/10/2010
PETER ....

I just resolve this problems using DataSet native objects, like this example:
http://www.telerik.com/community/forums/winforms/gridview/binding-radgridview-to-datatable-and-adding-items-to-datatable.aspx

Related

Advanced NoSQL Query (RavenDB)

I'm trying to run a query that gets all of my references, but it isn't working.
What I have right now is
from UserGroups
where Id="ActionGroup"
select Accomplishments.ID, Accomplishments.Accomplish
But I need only the Accomplishments.Accomplish that belong in my other collection ActivityAccomplishments and these are nested in another object.
To be exact, I'm trying to figure out how to query the UserGroups collection and only look at the one with id="ActionGroup". After that I need all of the Accomplishments.Accomplish strings within the UserGroup list to be filtered out if they don't match a id in ActivityAccomplishment.
Basically, in the UserGroup I'm looking at it's List Accomplishments needs to filter out all strings within the Acc class that don't match an Id in ActivityAccomplishments. Can someone please help me.
Here are the classes I'm using.
public class UserGroups
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Acc> Accomplishments { get; set; }
}
public class Acc
{
public string Id { get; set; }
public List<string> Accomplish { get; set; }
}
public class ActivityAccomplishments
{
public string Id { get; set; }
}
try this:
from UserGroups
where Id = "ActionGroup" AND Accomplishments[].Accomplish != "theIdYouDontWant"
select Accomplishments[].Accomplish as AccomplishStringsList
(not necessary to add the 'as AccomplishStringsList' - it is just a name for the results)

Current Row Wpf

I want to get the name I have in the DataGrid In Windows From
Code :
var PersonName = DataGridView.CurrentRow.Cells [1] .value.ToString ();
But in wpf, this method is not for DataGrid
That's not the WPF way. You need to work with the underlying collection that is the DataSource of your DataGrid and use the SelectedItem property.
You need to derive the value from the class that PersonName came from. For example, assume you have a Person class like this.
public class Person
{
public string PersonName { get; set; }
public string Address { get; set; }
public string Age { get; set; }
}
To get the PersonName from the current selected row, you could do something like this:
if (myDataGrid.SelectedItem != null)
{
var PersonName = ((Person)myDataGrid.SelectedItem).PersonName;
// ... now do something with the PersonName
}

Displaying Specific Fields from Facebook Graph API JSON

I'm trying to simply display the list of members in a specific group using the Facebook Graph API. I'm using Newtonsoft.JSON.
Here is the results of my url query:
Graph API Results
I used a JSON class generator and it gave me this:
public class Datum
{
public string name { get; set; }
public string id { get; set; }
public bool administrator { get; set; }
}
public class Cursors
{
public string before { get; set; }
public string after { get; set; }
}
public class Paging
{
public Cursors cursors { get; set; }
}
public class Members
{
public List<Datum> data { get; set; }
public Paging paging { get; set; }
}
public class RootObject
{
public Members members { get; set; }
public string id { get; set; }
}
I've tried every combination I can think of to display simply the list of members in a multi-line text box, but not sure if this is even the best way to display the list on a Windows Form App.
Could someone help me understand 2 things.
1) What is the best component to display the list of names in a Windows Form App?
2) What is the 1 or 2 lines to generate just the list of names using JsonConvert.DeserializeObject from this?
My raw data is stored in: string responseFromServer = reader.ReadToEnd();
To deserialize the JSON into your classes:
RootObject obj = JsonConvert.DeserializeObject<RootObject>(responseFromServer);
To get the member names into a List<string>:
List<string> members = obj.members.data.Select(d => d.name).ToList();
Note: You need to have using System.Linq; at the top of your file in order to use the Select and ToList methods.
As far as displaying the data in a windows form app, there's not a "best" component-- it depends on what you're trying to accomplish as to what control you would choose to use. For example, if all you want to do is display the list of names in a multi-line textbox, you could do this:
textBox1.Text = string.Join("\r\n", members);
If you want to allow the user to be able to select individual names and do something based on that selection, you would probably want to use a ListBox or a ComboBox instead. You can populate a ListBox or ComboBox like this:
listBox1.DisplayMember = "name";
listBox1.DataSource = obj.members.data;
That should be enough to get you started.

Hierarchical DataGrid Binding

I've gone brain dead on this...
I have a class something like
public class STDMBaseItem
{
public int Id { get; set; }
public string Name { get; set; }
public string Details { get; set; }
public STDMItemCollection Items { get; set; }
private STDMBaseItem Parent { get; set; }
public string FullName
{
get
{
if (Parent == null)
return Name;
else
return Parent.FullName + "/" + Name;
}
}
public STDMBaseItem()
{
Items = new STDMItemCollection();
}
}
public class STDMItemCollection : ObservableCollection<STDMBaseItem> { }
I am able to display items in a tree view fine, that is not my issue... I want to display it in a data grid with the columns: Id, FullName, Details
Data might look something like (1 item in main collection and 1 item in child collection):
ID | Item Name | Item Details
-- +--------------------+-------------------------
1 | First Item | Some Details
2 | First Item/Child | Some more details
The collection is named Items and is of type STDMItemCollection which has sub-items named Items of type STDMItemCollection (the same type)...
It seems like the XAML part should be simple, but I can't seem to get it.

Using score field with SolrNet

I'm using SolrNet and have a problem where the score field is conflicting with documents being added or updated in the index.
The class representing my documents looks something like this
class MyDoc
{
[SolrUniqueKey("doc_id")]
public string DocId { get; set; }
[SolrField("foo")]
public string Foo { get; set; }
[SolrField("bar")]
public string Bar { get; set; }
[SolrField("score")]
public double Score { get; set; }
}
In the query being issued to Solr, I've added the 'score' field to the fl parameter, and the score value is returned and set correctly on this class. However, when adding or updating documents, I'm getting an error about the score field not existing in my index, which it doesn't, and shouldn't as this is a dynamic field.
The code doing the add/update is fairly simple:
Startup.Container.GetInstance<ISolrOperations<MyDoc>>().Add(doc);
It looks like I need the score property to be ignored by SolrNet (or Solr) when adding or updating documents, and only use it when retrieving documents.
Is there any way to achieve this?
I have accomplished this by having two separate classes. One that maps to documents being retrieved from the index as search results and another class that is used to add items to the index. So in this scenario you could do the following:
class MyDoc
{
[SolrUniqueKey("doc_id")]
public string DocId { get; set; }
[SolrField("foo")]
public string Foo { get; set; }
[SolrField("bar")]
public string Bar { get; set; }
}
class MyDocResult
{
[SolrUniqueKey("doc_id")]
public string DocId { get; set; }
[SolrField("foo")]
public string Foo { get; set; }
[SolrField("bar")]
public string Bar { get; set; }
[SolrField("score")]
public double Score { get; set; }
}
Be sure you initialize both classes pointing to the same solr url.
Startup.Init("http://localhost:8983/solr");
Startup.Init("http://localhost:8983/solr");
Then you can add with:
ServiceLocator.Current.GetInstance<ISolrOperations<MyDoc>>().Add(doc);
And Query with:
var solr ServiceLocator.Current.GetInstance<ISolrOperations<MyDocResult>>();
var results = solr.Query("foo bar");
You could also look into using the Dynamic or Fully Loose Mapping options for SolrNet if you do not want to create two separate classes.
If you make your POCO class have the Score as nullable you can use the same object for indexing and results
[SolrField("score")]
public double? Score { get; set; }

Resources