|
The Chart control that ships with Visual Studio is more than capable of doing this.
|
|
|
|
|
Tools: Visual Studio 2010 Ultimate, Language C#, Database MySql
Hi,
I am searching this a while, but to date didn't find any suitable solution.
I've a form with bound DataGridView with 5 columns, ProductID, ProductName, Qty, Price and Amount. After normal data entry user can click button to save data to Mysql database, no problem there.
At present user is manually enter ProductID after which an Sql command is executed to fetch ProductName and sets it to DataGridView ProductName Column. I need a way to show a ListView below ProductID column when it got focus, so that user can select product (ProductID and ProductName) from ListView and set it to DataGridView's Row which user is currently using.
Is it possible to show listview below ProductID cell when user click or when got focus?
Thanks
Ahmed
|
|
|
|
|
You use a data or edit template.
Consider popping a dialog as your data entry tool, you will have infinitely more control over your UI and it is dramatically simpler to manage a dialog that faffing about with a DGV.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for the reply.
Using Dialog for data entry is good idea...but can you guide me about how can I show that dialog box when user click or enter in DataGridView row? better if it shows below the current row
|
|
|
|
|
Create the dialog for data entry
Add -
pop the dialog with a new instance of the object
save the new object to the database
add the saved object to the DGV collection
Edit
Trap the DGV double click event
Check for a selected row in the DGV
Pass the select rows data to the dialog
save the edited object to the database
update the selected rows object with the modifications.
Not sure if the last bit is required, it has been too many years since I did winforms
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Aaa...now I see where the misunderstanding starts...
Actually the requirement is not to do the Data entry via dialog but to get data from Dialog/list to DataGridView. That is why I need the listview at first place. The main form contain DataGridView, from which user can make data entry for each product. Which is working just fine for saving/editing/deleting data to database.
What I need to provide facility to the data entry process, and give the user a list to select product instead of typing ProductID, user can select product from list and it will copy to Datagridview's active Row alongwith its ProductDesc, the list should only show when user enter ProductID in DataGridView.
|
|
|
|
|
hello, looking for an algorithms/library in .NET that Algorithms which Max(x) Min(y)
I think "Mean Variance Optimization" is the word for it - however MVO is used for portfolio selection/optimization: Max(Mean) Min(Variance)
Some generic be nice and also how to find the edge cases? How optimized...?
Thanks
|
|
|
|
|
hi
I have a button named Button1 in my form, and a text box named TexBox1.
I've written code that when I click the Button1, a Radio button gets created with it's own name:
c#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace WebApplication7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Counter"] = 0;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
HtmlGenericControl div = new HtmlGenericControl("div");
for (int i = 0; i < Convert.ToInt32(ViewState["Counter"]); i++)
{
RadioButton rb = new RadioButton();
rb.GroupName = "GN1";
rb.ID = i.ToString();
rb.Text = "Button" + i.ToString();
rb.Checked = false;
rb.CheckedChanged += radioButton_CheckedChanged;
div.Controls.Add(rb);
Panel1.Controls.Add(div);
}
ViewState["Counter"] = Convert.ToInt32(ViewState["Counter"]) + 1;
}
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton btn = sender as RadioButton;
TextBox1.Text = btn.Text;
}
}
}
.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication7.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
the problem is after several radio buttons being created, i want the program works as if each of them is checked, the TextBox1.Text gets the radio button's text string
but the function radioButton_CheckedChanged doesnt execute
|
|
|
|
|
As you radio buttons are dynamic there will not be exist on the next post-back. You have to recreate them every time you got a post-back, so you have to maintain some state that tells you if there was radio buttons.
As now the only time you create the radio button is on Button.OnClick...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
thanks for the reply... i dont understand i tried to save the amount of buttons in ViewState["Counter"] , is that what i must do?
|
|
|
|
|
That not enough, you also have to recreate them outside the click event - which does not happening on other post-back events, like click on one of the radio buttons...
For instance you can add a loop of creation to page's OnLoad when it's post-back and the source isn't the button...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
When you check or uncheck the radio button, there is no code which does postback in your case. You have attached the event handler to the radio button but did not call the method.
|
|
|
|
|
Thanks for the reply.
may i know how to fix it? i am new to this programming language please guide me
|
|
|
|
|
I am trying to root out why this particular linq query is so expensive from a time standpoint, assuming it is the linq query that is causing it.
public static List<DocumentType> GetDocs()
{
List<DocumentType> output;
using (context = contextLogic())
{
output = (from d in context.DocumentTypes
select d).AsEnumerable().Select (x => new DocumentType
{
Id = x.iD,
Name = x.Name,
FlagA = x.FlagA,
IsActive = x.IsActive,
UpdateDate = x.UpdateDate,
CategoryName = x.DocumentCategory.Name,
Associations = string.Join(",", x.DocumentAssociations.Select(g => g.ADocID.ToString()))
}).ToList();
}
return output;
}
I tried flipping things around quite a bit. This was initially an observablecollection but it is a list right now as I try to tune it in different ways. Right now it is taking about 12 seconds to retrieve data from a table of 350 records. If I take out the CategoryName and the associations it times down to about six seconds, but that is still ridiculously slow.
|
|
|
|
|
Is the context local or is this on a server?
Try ruling out the new DocumentType by changing the .Select(...).ToList() to just be .Count() (change the assignment variable appropriately, it is just for testing...).
The .AsEnumerable() is totally unnecessary.
This is equivalent to what you have:
public static List<DocumentType> GetDocs()
{
using (var context = contextLogic())
{
return (from x in context.DocumentTypes
select new DocumentType {
Id = x.Id,
Name = x.Name,
FlagA = x.FlagA,
IsActive = x.IsActive,
UpdateDate = x.UpdateDate,
CategoryName = x.DocumentCategory.Name,
Associations = string.Join(",", x.DocumentAssociations.Select(g => g.ADocID.ToString()))
}).ToList();
}
}
|
|
|
|
|
Unfortunately, the AsEnumerable is necessary as L2E does not recognize string.Join. So you have to present it as an IEnumerable in order to join the Doc strings.
Regardless, I retooled the process to use a stored procedure but it is still a nightmare. The data access is fast, the stored procedure fills a list in less than a second, but assigning those items to the DocumentType model takes four or five seconds more.
It looks like it is the model itself. I am wondering if the implementation of INPC on the model is not causing a lot of slow down. Each time a new document type is added to the list it fires the OnPropertyChanged event for every single property. Not sure that is the problem, but it is a lot of events.
|
|
|
|
|
I had something a bit similar to this. I just put together SQL in the database to build the stuff I was trying to do in the LINQ query. This also involves changing your model so that it returns this field as a database calculated field so EF doesn't try to write to it.
|
|
|
|
|
I ended up moving all the data access logic to a SQL SP using STUFF for that very reason. The data access from SQL is a snap, but loading the data into the model is time consuming.
Frankly, I think that the nature of the design of the WPF screen is the issue. Each of the items is loaded into a list view and has two states, one editable state and one that is not editable. Any time you make a change to the property in the editable mode you have to fire the NotifyPropertyChanged event so that the UI will update it in the non-editable form.
As a result, every single property of every row fires an OnPropertyChanged event during the initial load. I think this is likely the problem. I just don't know how to work around it. If I could avoid that initial event firing I think that things would be much quicker.
|
|
|
|
|
XML File
<Log>
<HomeItem id="2">
<Time>1/8/2014 3:21:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>myDescrip</Description>
<Item/>
<Title/>
</HomeItem>
<HomeItem id="3">
<Time>1/8/2014 6:52:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>myDescrip2</Description>
<Item>
<ItemNumber id="0">
<Name>Coffee</Name>
<ItemDescrip>I Descrip1</ItemDescrip>
</ItemNumber>
<ItemNumber id="1">
<Name>Tea</Name>
<ItemDescrip>I Descrip 2</ItemDescrip>
</ItemNumber>
<ItemNumber id="2">
<Name>Milk</Name>
<ItemDescrip>I Descrip 3</ItemDescrip>
</ItemNumber>
</Item>
<Title/>
</HomeItem>
<HomeItem id="4">
<Time>1/8/2014 7:35:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>my Descrip 3</Description>
<Item>
<ItemNumber id="7">
<Name>Juice</Name>
<ItemDescrip>I Descrip 4</ItemDescrip>
</ItemNumber>
<ItemNumber id="8">
<Name>Tea</Name>
<ItemDescrip>I Descrip 6</ItemDescrip>
</ItemNumber>
<ItemNumber id="9">
<Name>Milk</Name>
<ItemDescrip>I Descrip 7</ItemDescrip>
</ItemNumber>
</Item>
<Title>The Title</Title>
</HomeItem>
<HomeItem id="5">
<Time>1/8/2014 12:21:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>myDescrip 8</Description>
<Item/>
<Title/>
</HomeItem>
</Log>
I want to loop through the results and assign variables. Here is my code
public void Today3()
{
XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
var q = from c in xDoc.Descendants("HomeItem")
select (string)c.Element("Description") + " " +
(string)c.Element("Time") + " Attribute = " +
(int)c.Attribute("id");
foreach (string name in q)
Console.WriteLine("My stuff = {0}", name);
}
My results are displayed as a string:(sample of results)
My stuff = myDescrip2 1/8/2014 6:52:47 PM Attribute = 3
My stuff = my Descrip 3 1/8/2014 7:35:47 PM Attribute = 4
How can I get the results to be like:
sDescrip = myDescrip2
time = 1/8/2014 6:52:47 PM
Id = 3
I tried name.value and q.value and many other combinations and can't come up with what I'm looking for.
Thank You
|
|
|
|
|
I'm not 100% sure if I understand your question correctly, but I could generate your desired result with this function:
public void Today3()
{
XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
var q = from c in xDoc.Descendants("HomeItem")
select new
{
Description=(string)c.Element("Description"),
Time = (string)c.Element("Time"),
Id=(int)c.Attribute("id")
};
foreach (var item in q)
Console.WriteLine(@"sDescrip = {0}
time = {1}
Id = {2}", item.Description, item.Time, item.Id);
}
Basically reading the XML elements into an anonymous type and using that to display the result.
modified 23-Jan-14 7:50am.
|
|
|
|
|
Thank You, I have one more step to go. I'm getting the values into the variables, the only issue is getting the values that are in the item element.
<Item>
<ItemNumber id="0">
<Name>Coffee</Name>
<ItemDescrip>I Descrip1</ItemDescrip>
</ItemNumber>
<ItemNumber id="1">
<Name>Tea</Name>
<ItemDescrip>I Descrip 2</ItemDescrip>
</ItemNumber>
</Item>
The tricky part to me is that sometimes they exists and other times they don't.
|
|
|
|
|
In what kind of data structure do you need them in your program? Or do you just need to write them to the console?
If so, in which format should it be written to the console? Can you give an example?
|
|
|
|
|
I will be writing the records to a database. I thought the best way of doing that was getting the data into a datatable. to do that I need to add rows and populate the columns with the individual elements or attributes. The element Item and ItemNumber are only present in some conditions.
So when I add them to the variables I should see something like this:
+If all items exist
Time = (string)c.Element("Time"),
Description = (string)c.Element("Description"),
ItemId = (int)c.Attribute("Itemid"), ***Note not HomeItemId****
Name = (string)c.Element("Name"), //Coffee
ItemDescrip = (string)c.Element("ItemDescrip"),
+If NO items exist
Time = (string)c.Element("Time"),
Description = (string)c.Element("Description"),
ItemId = ""
Name = ""
ItemDescrip = ""
Thanks,
Sue
|
|
|
|
|
Try that one, joining with subItems and adding a null item in the case that no subitem exists:
public void Today3()
{
XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
var q = from homeItem in xDoc.Descendants("HomeItem")
from subItem in homeItem.Element("Item").Descendants("ItemNumber").Any () ? homeItem.Element("Item").Descendants("ItemNumber") : new List<XElement>(){null}
select new
{
Description=(string)homeItem.Element("Description"),
Time = (string)homeItem.Element("Time"),
Id=(int)homeItem.Attribute("id"),
ItemId = subItem == null ? "" : (string)subItem.Attribute("id"),
Name = subItem == null ? "" : (string)subItem.Element("Name"),
ItemDescrip = subItem == null ? "" : (string)subItem.Element("ItemDescrip")
};
foreach (var item in q)
Console.WriteLine(@"Description = {0}
Time = {1}
Id = {2}
ItemId = {3}
Name = {4}
ItemDescrip = {5}
--------------", item.Description, item.Time, item.Id, item.ItemId, item.Name, item.ItemDescrip);
}
|
|
|
|
|
That's exactly what I need.
Thank You So Very Much!
|
|
|
|