I am using Entity Framework and DevExpress 10.5 XtraGrid.
Imagine that we have entities
So my point is to display them in Form using XtraGrids and master-details.
The Level tree of gridControl should look like this:
So I have implemented events for MainGrid like this
#region gridView1_enents
private void gridView1_MasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e)
{
districts c = (districts)gridView1.GetRow(e.RowHandle);
e.IsEmpty = c.districtparts.Count == 0;
}
private void gridView1_MasterRowGetRelationCount(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationCountEventArgs e)
{
e.RelationCount = 1;
}
private void gridView1_MasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e)
{
e.RelationName = "districtparts";
}
private void gridView1_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
{
districts c = (districts)gridView1.GetRow(e.RowHandle);
e.ChildList = new BindingSource(c, "districtparts");
}
#endregion
and that works fine: there is a grid, displaying my districts and I can expand each row and there displays another grid with districtparts
The question is: what should I do to display votecallers. The goal is to have two levels of master-detail hierarchy. That means that districts should have districtparts, and districtparts should have votecallers.
Thanks.
Found a solution here
And some irrelevant words to meet the requirement of 30 characters =)
Related
I have below code written inside C# Form application where I am trying to get x,y and z co-ordinates from Leap Motion device.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//controller.EventContext = WindowsFormsSynchronizationContext.Current;
button1.Click += new EventHandler(button1_Click);
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
// Initialize the Controller object which connects to the Leap motion service
// and captures the hand tracking data
Controller controller = new Controller();
//Get the most recent tracking data using the Frame object
Frame frame = controller.Frame();
for (int h = 0; h < frame.Hands.Count; h++)
{
// Initialize the Hand in the given frame
Hand leapHand = frame.Hands[h];
// Get the "Pointer" finger of current hand which refers to where a person is pointing
Finger leapFinger = leapHand.Fingers[1];
// Prepare a vector which will store the co-ordinate values of the tip of the pointer
Vector currentPosition = leapFinger.StabilizedTipPosition;
textBox1.Text = Convert.ToString(currentPosition.x);
textBox2.Text = Convert.ToString(currentPosition.y);
textBox3.Text = Convert.ToString(currentPosition.z);
}
}
}
However, I need to explicitly click the button1 to display.
Any idea what's wrong ?
Here is an overly simple example of one way to do it. I'm not saying it's the best way, but you should be able to modify this sample code with your code.
In this example, there is a simple "HelloWorld" method that is called when the form is initialized as well as whenever you press the button. Let me know if this gets you close to what you're after.
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
HelloWorldTest();
}
private void button1_Click(object sender, EventArgs e)
{
HelloWorldTest();
}
private void HelloWorldTest()
{
MessageBox.Show("Hello World!");
}
}
}
For what it's worth, I didn't use your code because I don't have the Leap libraries installed and if there was a typo, I wouldn't be much help to resolve it. Nonetheless, hopefully it gets you going down the right path.
I don't have a good understanding of MVVM and have read some articles on other pages.
Does the ViewModel do all the business logic and interact with data model which then send the data to the view for presentation.
On the View, will only have function that related directly UI.
This is my code I have code but not sure is it the correct way to do it
private TestingViewModel Model
{
get
{
return BindingContext as TestingViewModel;
}
}
public TestingPage()
{
InitializeComponent();
BindingContext = new TestingViewModel();
Model.PropertyChanged += TestingPropertyChanged;
NavigationPage.SetHasNavigationBar(this, false);
NavigationPage.SetHasBackButton(this, false);
MediaFactory.ClearAllCachedMedia();
SetupTappedControl();
}
private void TestingPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals("ActivePage"))
{
if (Model.ActivePage != null)
{
Device.BeginInvokeOnMainThread(async () =>
{
var path = await MediaFactory.GetImagePathAsync(Model.ActivePage.DocumentId + "_" + Model.ActivePage.PageNumber);
CanvasView.Strokes = Model.ActivePage.Strokes;
CanvasView.LoadBitmapInMemory(path, Model.ActivePage.Width, Model.ActivePage.Height);
});
}
}
}
#region File Button Selected
public void TapFileOpen(object sender, EventArgs e)
{
Task.Run(() =>
{
var pickFileTask = CrossFilePicker.Current.PickFile();
var data = pickFileTask.Result;
Model.OpenDocument(data.FileName, data.DataArray);
});
}
Question 1: Why I have to pass it to a BindingContext if I can just hold TestingViewModel object in the Code-behind class of the View?
The line below :
CanvasView.Strokes = Model.ActivePage.Strokes;
CanvasView.LoadBitmapInMemory(path, Model.ActivePage.Width, Model.ActivePage.Height);
Question 2 : The Strokes is a collection of stroke object. Do Strokes
also a ViewModel.
The Idea of the MVVM is to separate concern between creating Views and business logic.
the ViewModel will manage your business logic including implementation of Properties and Commands or RelyCommands that you will later on bind it into your views, So simple you will not have any code behind in your views on best case.
For better understanding for this pattern, I would suggest you to read this msdn link that will illustrate to you how can you re-structure your code for better use and what are the benefits from using MVVM
I show fields in customization form. I choose Excel2007 as CustomizationFormStyle but I would like to show just Filter area. I want Column, Row and Data area to be invisible.
How can I manage this?
pivotGridControl1.OptionsCustomization.CustomizationFormStyle = DevExpress.XtraPivotGrid.Customization.CustomizationFormStyle.Excel2007;
pivotGridControl1.OptionsCustomization.CustomizationFormLayout = CustomizationFormLayout.BottomPanelOnly1by4;
pivotGridControl1.OptionsCustomization.CustomizationFormAllowedLayouts = CustomizationFormAllowedLayouts.BottomPanelOnly1by4;
You need to use PivotGridControl.ShowingCustomizationForm event and PivotGridControl.ShowCustomizationForm event. In PivotGridControl.ShowingCustomizationForm event you need to get CustomizationForm object from CustomizationFormShowingEventArgs.CustomizationForm property and use this object in PivotGridControl.ShowCustomizationForm event to customize the customization form. To get the filter area and other area objects, you need to use CustomizationForm.BottomPanel property and its GetAreaLabel, GetAreaIcon and GetAreaList methods.
Here is example:
private void pivotGridControl1_ShowingCustomizationForm(object sender, CustomizationFormShowingEventArgs e)
{
_customizationForm = e.CustomizationForm as CustomizationForm;
}
private void pivotGridControl1_ShowCustomizationForm(object sender, EventArgs e)
{
var bottomPanel = _customizationForm.BottomPanel as ExcelCustomizationFormBottomPanel;
var areas = new PivotArea[] { PivotArea.ColumnArea, PivotArea.RowArea, PivotArea.DataArea };
foreach (var area in areas)
{
bottomPanel.GetAreaLabel(area).Hide();
bottomPanel.GetAreaIcon(area).Hide();
bottomPanel.GetAreaList(area).Hide();
}
var filterAreaList = bottomPanel.GetAreaList(PivotArea.FilterArea);
var dataAreaList = bottomPanel.GetAreaList(PivotArea.DataArea);
filterAreaList.Height = dataAreaList.Bottom - filterAreaList.Top;
}
I have 2 forms. form1 and form2. There is a button at form1 for me to access to form2 and in form2, I have a listview2 and some textboxes. I manage to input items into listview2. Then when I click on the OK button in form2, listview1 in form1 should show exactly like listview2. So guys, can anyone suggest me a way to do this? Thanks
Below are my codes. I hope I don't confuse you all.
Form1 code =>
namespace MainServerPage
{
public partial class MainServerPage : Form
{
public ListView LV;
public MainServerPage()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
AddItem Add = new AddItem(this); //to open form2
Add.ShowDialog();
}
}
}
Form2 code =>
namespace MainServerPage
{
public partial class AddItem : Form
{
MainServerPage currentform; //I learn this way of passing form to another but it's not working
public AddItem(MainServerPage incomingform)
{
currentform = incomingform;
InitializeComponent();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem(txtCode.Text);
item.SubItems.Add(txtLocation.Text);
item.SubItems.Add(cbxStatus.Text);
item.SubItems.Add(txtWeatherHigh.ToString());
item.SubItems.Add(txtWeatherLow.ToString());
listView2.Items.Add(item); //send to listView2
txtCode.Text = "";
txtLocation.Text = "";
cbxStatus.Text = "";
txtWeatherHigh.Text = "";
txtWeatherLow.Text = "";
cbxZone.Text = "";
}
private void btnOk_Click(object sender, EventArgs e)
{
currentform.LV = load; //I got stuck here...do not know what to do
}
}
}
In general, it's not the list view you want to pass, it's the data that the list view is representing. You should probably rethink your design such that you btnUpdate_Click function builds a data object rather than building a ListViewItem directly. Then you can either pass the data object(s) back to your first form.
I have a page that uses a large filtered EF object in several datagrids so each datagrid displays a different "Status". The page code is getting a bit out of control so I wanted to seperate the sections out into usercontrols. I only want to get the data once so I want to be able to pass the properly filtered data object list to the appropriate usercontrol. I'm just not sure how to go about it. Any suggestions?
Thanks,
Rhonda
My data object
activeDisplayChecklist = allDisplayChecklist.Where(x => x.ChecklistStatus.ToString().ToUpper() != Checklist.ChecklistStatus.Approved.ToDescriptionString().ToUpper() && x.ChecklistStatus.ToString().ToUpper() != Checklist.ChecklistStatus.Canceled.ToDescriptionString().ToUpper()).ToList();
Workqueue.ascx.cs
public partial class WorkQueue : System.Web.UI.UserControl
{
public List<Entities.Checklist> activeChecklists { get; set; }
private List<AMWOTPortalDisplay> ActiveDisplayChecklist = new List<AMWOTPortalDisplay>();
public List<AMWOTPortalDisplay> activeDisplayChecklist
{
get
{
return ActiveDisplayChecklist;
}
set
{
ActiveDisplayChecklist = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
PopulateWorkQueueGrid();
}
//show statuses that require approval (Submitted or CTO Exception)
//public void PopulateWorkQueueGrid(List<AMWOTPortalDisplay> ActiveDisplayChecklist)
public void PopulateWorkQueueGrid()
{
// ActiveDisplayChecklist is alway Count = 0 or null.
List filteredChecklist = ActiveDisplayChecklist.Where(x => x.ChecklistStatus.ToString().ToUpper() == Checklist.ChecklistStatus.Submitted.ToDescriptionString().ToUpper() || x.ChecklistStatus.ToString().ToUpper() == Checklist.ChecklistStatus.CTOException.ToDescriptionString().ToUpper()).ToList();
WorkQueueGrid.DataSource = filteredChecklist.ToList();
WorkQueueGrid.DataBind();
}
}
<WQ:WorkQueueList ID="WorkQueueList" runat="Server"></WQ:WorkQueueList>
portal.aspx.cs (the objects contain 9 and 12 rows here)
WorkQueue wq = new WorkQueue();
wq.activeChecklists = activeChecklists.ToList();
wq.activeDisplayChecklist = activeDisplayChecklist.ToList();