Telerik RadListView Binding Issue in Xamarin forms - c#

I'm facing problem in binding the data radlistview by using it in xamarin forms. The code mentioned below is working fine with me in a single array
var listView = new RadListView();
listView.ItemsSource = new List<string>() { "A", "B", "C" };
but when to use the syntax of binding in multidemensional array like this
List<List<string>> strings = new List<List<string>>()
{
new List<string>{"Id:001","Name:Decker1"},
new List<string>{"Id:002","Name:Decker2"}
};
Data is not binding. The data is coming from Api
Please help figure out the problem where im missing and guide me so that i can bind the data in radlistview of telerik from api.

Your first list is just a list of strings so the listview can just do a ToString and get the value.
The second one if it does a ToString it wont get any string just a System.Object or something similar.
You either need to create a list of classes with properties and define these in the listview or flatten your multi dimensional array into a single dimension again.

Related

Generating Table & Cell in Xamarin iOS

I have a problem generating a table view from array json data that I have get.
I have completed of getting and saving the json data in array form, but the problem I facing is that I cannot load them into my table.
Below is my code,
client.ExecuteAsync(request, response =>
{
string json = response.Content;
Console.WriteLine(json);
List<PostInfo> curTest = JsonConvert.DeserializeObject<List<PostInfo>>(json);
for (int i = 0; i < curTest.Count; i++)
{
PostInfo t1 = curTest[i];
arraydata.Add(t1.title.rendered);
}
array1 = arraydata.ToArray();
});
UITableView _table;
_table = new UITableView
{
Frame = new CoreGraphics.CGRect(0, 20, View.Bounds.Width, View.Bounds.Height - 20),
Source = new TableSource(array1)
};
View.AddSubview(_table);
The table returns a blank page when I trying to put the array1 as my TableSource. And I believe that if the array1 has nothing in the array once it out from the client.ExecuteAsync.
Can someone guide me how to generate TableView based on array get from the json data?
Your problem here is that when you try assign data source to your table view the array is still empty. Short term solution would be - re-assign datasource in async operation closure and dont forget to call TableView.ReloadData(). But it's not the prettiest solution. I would suggest you MVVMCross - You write your Core project with business logic and then you create platform project and use bindings to bind say Datasource to a collection of items. You can find tutorials with source code on the internet. There are plenty of them.
Your view doesn't realise that the source has changed. Big chance that if you get it working and change the properties of objects in your array, your view also won't know its data has changed.
Take a look at this:
https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx
Basically what this interface does is tell the view or binding that something has changed. This way the view knows not only to update, if you are smart about it it only updates 1 value, the one that changed.
Now for your current problem, how to fix it with this interface? Simply change your array to an ObservableCollection -> https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx
An ObservableCollection is like a List but it already has the INotifyPropertyChanged interface implemented.

How to add a revit DB built-in-category list to a listbox on a form

If I try to use addrange to add this list "builtInCats_List = new List<BuiltInCategory>();,"
to a list box I get the following error below.
cannot convert from
'System.Collections.Generic.List'
to 'System.Windows.Forms.ListBox.ObjectCollection'
How can I populate the listbox on a form with the revit.db list of element category types?
Looks like addrange needs an array to work.
http://msdn.microsoft.com/en-us/library/z018s5az(v=vs.110).aspx
Do you have a collection of Elements that are of a specific builtInCategory?
If so, convert your list items to an element array[] and try again.
For example, if you looking to add 'Walls' to the listbox using addrange:
Autodesk.Revit.DB.Element[] Walls = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).ToElements().ToArray();
Try to convert your List to an Array:
yourListBox.ObjectCollection.AddRange(builtInCats_List.ToArray());
These lines of code populate the listbox, I found this by skimming through the building coder site. Thanx for your assistance.
lstb1.DataSource = builtInCats_List;
lstb1.DisplayMember = "Name";

Static array in C# ASP .Net

I am getting a strange problem.
I have a static method which is in common DLL and returns a static array of countries from the database.
And using this common method, I am trying to fill a Drop down of Country.
So code will be as below.
In Common - Helper Class DLL code
public static string[] Countries()
{
string qry = "select * from Countries";
Dataset result=SqlHelper.ExecDS(qry);
countryArray = new string[100];
//Filing country array
return countryArray;
}
In the current project
countryOptions = new string[100];
countryOptions = Common.Helper.Countries();
I know Drop Down should be bind with DS only but as his is in common DLL i cannot change this.
But now only problem I am facing is even if delete a row from Countries table it is effect is not coming in Countries array.
Common.Helper.Countries() is still returns that row. I have double checked that the row has been deleted but its effect is not coming. Can someone please help me with this??
I know Drop Down should be bind with DS only
if you mean Drop Down list can only bind with DataSet, that is not correct. See Binding DropDownList Using List Collection, Enum and DataSet in ASP.NET
if I delete a row from Countries table it is effect is not coming in
Countries array
put a break point on the following line, see if the array is getting populated.
countryOptions = Common.Helper.Countries();
Call dropDownList.DataBind(); to refresh the drop down list
How do you fill the array? I think this is where the error occurs.
Besides, your array does not need to be initialised twice:
// Creates a 100-item-array that is never actually used, so
// this line looks unnecessary
countryOptions = new string[100];
// Creates another array on the heap, leaving above array
// to GC
countryOptions = Common.Helper.Countries();
Actually the problem was since array is static i must need to restart IIS otherwise it will take the same value.

C# Referencing a dataSets property without using it's name

Anyone know how to reference a dataSet for example if I called it dataSet5 and don't want to use it's name.
For example if I would normally use this call to display a particular tables cell value
MessageBox.Show(dataSet5.Tables[0].Rows[0][0].ToString());
How can I do the same as above using indexing so I can throw it in an incrementing loop similar to below which doesn't work. I was hoping maybe it's either part of an array of form elements or components that way I can access it something like below.
MessageBox.Show(dataSets[24].Tables[0].Rows[0][0].ToString());
Using SharpDevelop
If you want to call datasets by index you have to have an array of dataset.
DataSet[] alldatasets = new DataSet[5];
Even better if you put the datasets in a List. IE.
List<DataSet> listDatasets = new List<DataSet>();
listDatasets.Add(new DataSet());
listDatasets[0].Tables[0].Rows[0][0].ToString();
You need to put the DataSets into your own array:
private DataSet[] dataSets;
...
dataSets = new DataSet[] { ... };

How to get an Item from an auto-populated DataGrid?

I have a DataGrid that is automatically fed certain values from an LINQ-To-SQL-Source. The headers of the DataGrid are also auto-generated. I simply want one of the Cells of the currently selected item within the data-grid.
var a = TestGrid.SelectedCells[0].Item;
If I debug this I get a List containing all the values I need:
TestGrid.SelectedCells[0].Item{ Datum = {11.05.2011 00:00:00}, ID = 3, name = "db",Status = "Ready" }<Anonymous Type>
I have absolutely no idea how to select the second item(ID) from that anonymous type, and google isn't helping
The best option would be to create a type to hold your values and store that in your DataGrid. If you're only using it for display, the anonymous types are fine to use. The moment you need to use them for anything else, they are not so great.
If you really want to stick to anonymous types, the only option you have is to use reflection. If this is specifically a C# 4.0+ app, then using dynamic can make this somewhat easier.

Categories