I try to create a GridPanel programmatically using a LinqDataSource as shown in the examples.
So far I can see my empty GridPanel without any data inside cause my GridPanel is missing the ColumnModel used to show the data.
As I can't find the right method to add the ColumnModel to the GridPanel I need to ask you.
My Code which is used to create my GridPanel and everything is underneath.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace IntraNET_Prototype
{
public partial class MitarbeiterUndTelefonliste : System.Web.UI.Page
{
public LinqDataSource MitarbeiterDataSource = new LinqDataSource();
public Ext.Net.GridPanel MitarbeiterGridPanel = new Ext.Net.GridPanel();
public Ext.Net.Store MitarbeiterStore = new Ext.Net.Store();
public Ext.Net.JsonReader MitarbeiterJSONReader = new Ext.Net.JsonReader();
public Ext.Net.ColumnModel MitarbeiterColumnModel = new Ext.Net.ColumnModel();
public MitarbeiterUndTelefonliste()
{
}
protected void Page_Load(object sender, EventArgs e)
{
MitarbeiterDataSource.ID = "MitarbeiterDataSource";
MitarbeiterDataSource.ContextTypeName = "MitarbeiterlisteEntities";
MitarbeiterDataSource.TableName = "Mitarbeiterliste";
MitarbeiterGridPanel.ID = "MitarbeiterGridPanel";
MitarbeiterGridPanel.Title = "MitarbeiterListe";
MitarbeiterGridPanel.AutoWidth = true;
MitarbeiterGridPanel.Frame = true;
MitarbeiterGridPanel.Height = 570;
MitarbeiterStore.ID = "MitarbeiterStore";
MitarbeiterStore.DataSource = MitarbeiterDataSource;
MitarbeiterColumnModel.ID = "MitarbeiterColumnModel";
MitarbeiterColumnModel.Columns.Add(new Ext.Net.Column() { DataIndex = "primaerschluessel", Header = "Index", Width = 50 });
MitarbeiterJSONReader.Fields.Add(new Ext.Net.RecordField() { Name = "primaerschluessel" });
MitarbeiterGridPanel.Store.Add(MitarbeiterStore);
this.Form.Controls.Add(MitarbeiterGridPanel);
}
}
}
Thanks in advance for any help! I appreciate any suggestions, critics and any help!
You can't assign some column model to the grid. Because it's read-only property.
You have to use MitarbeiterGridPanel.ColumnModel.Columns.Add() instead of MitarbeiterColumnModel.Columns.Add()
Related
Dear fellow programmers.
Currently my strings are loaded, and 5 buttons are created with these titles from the database.
Yet the buttons are not visible on the iOS app.
What am I missing.
I am using Xamarin.iOS and c#
Thanks in advance
using Foundation;
using UIKit;
using System.CodeDom.Compiler;
using System.Drawing;
using Ola.ServiceClients;
using System.Threading.Tasks;
using PortableRest;
using Ola.Shared.Models;
using System.Net.Http;
using System.Net.Http.Headers;
namespace Ola.iOS
{
partial class NavigationViewController : UIViewController
{
//private MenuItem[] menuItems;
private MenuItem[] drawerItems;
public string token = "";
public NavigationViewController(IntPtr handle)
: base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
LoadMenu();
}
public async void LoadMenu()
{
RestResponse<MenuItem[]> response = await NavigationClient.Current.GetMenu(token);
//HttpResponseHeaders responseHeaders = response.HttpResponseMessage.Headers;
//HttpRequestMessage requestMessage = response.HttpResponseMessage.RequestMessage;
if (response != null && response.Content != null && response.Content.Length > 0)
{
//menuItems = response.Content;
for (int i = 0; i < response.Content.Length; i++)
{
UIButton button = UIButton.FromType(UIButtonType.RoundedRect);
button.SetTitle(response.Content[i].Text, UIControlState.Normal);
this.Add(button);
System.Console.WriteLine("Button created");
}
System.Console.WriteLine();
}
}
}
}
Greetings
Dave
Add the following code to show your buttons:
this.View.AddSubview(button);
instead of:
this.Add(button);
Make sure you are setting button.Frame property, adding button to parent View and also you should try to set background color as by default its transparent.EditI'm not sure if that will make any difference but try to create buttons differently e.i var button = new UIButton(new RectangleF());And one more thing I'm thinking of may be transparency, make sure that parent View and buttons do not have alpha set to 0Edit 2One more thing ! Try wrap call where you adding buttons to view by calling it in InvokeOnMainThread(() =>
{
this.View.AddSubview(button);
});
method !
I created three text boxes calls HighOffSetX, HighOffSetY, and HigOffSetZ.
I want to add them to a list called HighOffSets. The problem that I am running into is how to add the text boxes into a list in another class.
When I try to add HighOffSetX to my list I get an error that HighOffSetX is not recognized. What do I do so my class recognizes the text boxes? I do not have a lot of experience in GUIs with C#. I looked on Google and stack and could not find an answer that helped me out. Here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace UCAGui
{
public class CaliberationGUI: Form
{
List<TextBox> HighOffSets = new List<TextBox>();
public CaliberationGUI()
{
HighOffSets.Add(this.HighOffSetX); //This line gives me an error
}
}
}
I changed the names of the text boxes to HighOffSetX, HighOffSetY, and HigOffSetZ. Here is the generated code from ConfigForm.Designer.cs
this.HighOffSetX.Location = new System.Drawing.Point(60, 28);
this.HighOffSetX.Name = "HighOffSetX";
this.HighOffSetX.Size = new System.Drawing.Size(100, 20);
this.HighOffSetX.TabIndex = 5;
If you want me to post the generated code C# created when I added the text boxes let me know.
You have declared your textbox in a different form.You can't access that textbox without an instance of ConfigForm.Create a new instance of your second Form, or pass it via the constructor:
public class CaliberationGUI: Form
{
private ConfigForm configForm;
List<TextBox> HighOffSets = new List<TextBox>();
public CaliberationGUI(ConfigForm config)
{
InitializeComponent();
this.configForm = config;
HighOffSets.Add(this.configForm.HighOffSetX);
}
}
In my app I have a list activity and in it you can check multiple items in the list, how can I have the checked items checked the next time the listactivity is opened? I think the way to do it is through using getview but I dont know how to implement that in my class because I am not using a custom listadapter, if someone could show me how that would be great
Below is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Linq;
namespace BoostITAndroid
{
[Activity(Label = "My Activity")]
public class Selector : ListActivity
{
int[] numlist = new int[45];
String[] Options;
int[] OptionsID;
String item;
int counter = 0;
Button save, cancel;
int vehicleId;
int category;
private List<AvailableFeatures> list;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
List<Makes> listmakes = VehicleAssetsDB.GetMakes();
Options = new String[listmakes.Count];
OptionsID = new int[listmakes.Count];
Options = listmakes.Select(Makes => Makes.Make).ToArray();
OptionsID = listmakes.Select(Makes => Makes.ID).ToArray();
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, Options);
}
}
}
Below is my onclicklistener
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
l.ChoiceMode = ChoiceMode.Multiple;
Android.Util.SparseBooleanArray checkedItems = l.CheckedItemPositions;
if (!checkedItems.Get(position))
{
l.SetItemChecked(position, false);
}
if (checkedItems.Get(position))
{
l.SetItemChecked(position, true);
}
}
if you want your checkboxes to retain their state, you have to save that somewhere in persistent storage. Depending on the purpose of the checkbox, you could store the state in SharedPreferences, or you could create a SQLite DB and store the values there.
Either way, you will likely need a custom Adapter to display your list and set the checkbox states depending on the saved state of each.
See here for details = http://developer.android.com/guide/topics/data/data-storage.html
Hope that helps.
I want to write query smn.ParentNode.ChildNodes. If ShowInNavigation value false, I don't want to show. Telerik Site map node has this att. Ho to do this?
using System;
using System.Web;
using Telerik.Sitefinity.Web;
using System.Linq;
using System.Data;
public partial class CustomTemplate_Navigation : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SiteMapNode smn = SiteMapBase.GetCurrentProvider().CurrentNode;
while (smn.ParentNode != null)
{
if (smn.ParentNode.ParentNode == SiteMap.RootNode)
{
siteMapControl_verticaltree.DataSource = smn.ParentNode.ChildNodes;/*this line will be write query*/
siteMapControl_verticaltree.DataBind();
break;
}
smn = smn.ParentNode;
}
}
}
something like this:
smn.ParentNode.ChildNodes.AsQueryable().Where(x => x.ShowInNavigation).ToList();
You could do somthing like this: (you should not only Linqify, but you need a cast also)
(I used this in a .NET MVC4 project)
SiteMapNodeCollection coll = SiteMap.RootNode.ChildNodes;
IEnumerable<SiteMapNode> nodes = coll.Cast<SiteMapNode>();
var query = from node in nodes where Boolean.Parse(node["ShowInNavigation"]) == true select node;
Been a while and I've volunteered to teach myself Windows programming at my company. Started writing vbs scripts and suddenly realized how incredibly useful this programming thing is ;-)
Anyway, I'm a total newbie at C# AND Visual Studio, I kind of get how it works, you drag and drop interface pieces in the design side then wire them together in the back/program side.
I'm trying to write a program that will (ultimately) read in a (very specific kind of) csv file and give the user a friendlier way to edit and sort through it than Excel. Should be simple stuff, and I'm excited about it.
I started this morning and, with the help of the internet, got as far as reading in and parsing the CSV (which is actually a TSV, since they use tabs not commas but hey).
I've been trying to figure out the best way to display the information, and, for now at least, I'm using a DataGridView. But the data isn't displaying. Instead, I'm seeing a long grid of values with column headers of Length, LongLength, Rank, SyncRoot, IsReadOnly, IsFixedSize, and IsSynchronized.
I don't know what any of these mean or where they come from, and unfortunately I don't know how change them either. Maybe somebody can help?
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace readInCSV
{
public partial class readInCSV : Form
{
public readInCSV()
{
InitializeComponent();
}
public List<string[]> parseCSV(string path)
{
List<string[]> parsedData = new List<string[]>();
try
{
using (StreamReader readfile = new StreamReader(path))
{
string line;
string[] row;
while ((line = readfile.ReadLine()) != null)
{
row = line.Split('\t');
parsedData.Add(row);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return parsedData;
}
//PRIVATE METHODS FROM HERE ON DOWN
private void btnLoadIn_Click(object sender, EventArgs e)
{
int size = -1;
DialogResult csvResult = openCSVDialog.ShowDialog();
if (csvResult == DialogResult.OK)
{
string file = openCSVDialog.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch (IOException)
{
}
}
dgView.Dock = DockStyle.Top;
dgView.EditMode = DataGridViewEditMode.EditOnEnter;
dgView.AutoGenerateColumns = true;
dgView.DataSource = parseCSV(openCSVDialog.FileName);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void openCSVDialog_FileOk(object sender, CancelEventArgs e)
{
}
}
}
Thanks in advance!
What's happening here is that the DataGridView is trying to display all the information for each of the string arrays in your parsedData List.
When you set a DataGridView's DataSource as a List of objects, it attempts to interpret each of the objects as a row to display. parsedData is a List of string array objects, so the grid is showing you all the displayable properties for an array object.
What we can do is parse each TSV row into a custom class (call it TsvRow) which has all the relevant data exposed. The TsvRow objects are then placed in a List and passed to the DataGridView. An example of this approach is explained in this article.
For example:
public class TsvRow
{
// Properties to hold column data
public string Column1 { get; set; }
public string Column2 { get; set; }
}
...
public List<TsvRow> parseCSV(string path)
{
List<TsvRow> parsedData = new List<TsvRow>();
try
{
using (StreamReader readfile = new StreamReader(path))
{
string line;
string[] row;
while ((line = readfile.ReadLine()) != null)
{
row = line.Split('\t');
// Here we assume we know the order of the columns in the TSV
// And we populate the object
TsvRow tsvRow = new TsvRow();
tsvRow.Column1 = row[0];
tsvRow.Column2 = row[1];
parsedData.Add(myObject);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return parsedData;
}
Since all your column data is exposed as properties (i.e. "Column1" and "Column2"), they should be reflected in the DataGridView automatically.
Hope that helps! Please let me know if this needs clarification.
The DataGridView tries to display the Properties of your string-Array. You should set AutoGenerateColumns = false and create the columns by yourself.
Would the first line of the CSV/TSV contain the column names? Is so, you shouldn't pass them as DataSource.
dgView.AutoGenerateColumns = false;
foreach(string name in columnNames)
{
dgView.Columns.Add(name, name);
}