|
I do not write according to a DataSet or DataTable, this writing style I would use, I heard stores Procedures writing style program will run faster, secure, more... should I try writing style stores Procedures. follow you write Stores Procedures how to assign values to gridview.DataSource ? if you write that you have to answer any of my eye.
|
|
|
|
|
I don't understand what you are asking. However, stored procedures do ten to execute faster because they can already be compiled. But you don't want to create a stored procedure that creates a function. Either use a stored procedure or a function.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Thank you for help me, I did it. but I cryptichard (don't understand) declare procedures CREATE PROCEDURE return value list, while I declare CREATE FUNCTION don't return list or table.
|
|
|
|
|
Since a WinForm's (in the standard case where the WinForm Parent == null) Bounds are in screen-co-ordinates, I would expect using RectangleToScreen on the Form's Bounds would give the same result as just inspecting the Bounds, but, this is not true:
> ? this.Bounds
{X = 230 Y = 84 Width = 900 Height = 600}
> ? RectangleToScreen(this.Bounds)
{X = 469 Y = 200 Width = 900 Height = 600}
curiously, Bill
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : ‘I know all about it. I've already found it.’
As far as I'm concerned, the word means: ‘I am looking. I am hunting for it. I am deeply involved.’” Vincent Van Gogh
|
|
|
|
|
Why Bill?
RectangleToScreen[^] converts Client coordinates to Screen values, and the Bounds[^] property is relative to it's Parent container. So if you try to convert Bounds with no Parent, you are converting Screen Coords to Screen coords, and it all goes agly.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Brother OriginalGriff, I am consoled by your kind words, but the irritating thought remains, like a spiny-burr in my sandal, that translating screen co-ordinates to screen co-ordinates should return (drum roll) ... screen co-ordinates.
However, mea culpa, I forgot, for a moment, that programming is a form of the Mad Hatter's Tea Party.
cheers, Bill
“I'm an artist: it's self evident that word implies looking for something all the time without ever finding it in full. It is the opposite of saying : ‘I know all about it. I've already found it.’
As far as I'm concerned, the word means: ‘I am looking. I am hunting for it. I am deeply involved.’” Vincent Van Gogh
|
|
|
|
|
Translating screen co-ords to screen co-ords does work - but you aren't.
What you are doing is passing co-ords to a method expecting client co-ords and telling it they are relative to the client (when they are actually relative to it's parent, the desktop) - so it offsets them by the client location in it's parent, as it's supposed to do.
OT: How's Thailand these days? We have nothing on our news due to some silly WendyBall contest in Rio.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
BillWoodruff wrote: translating screen co-ordinates to screen co-ordinates should return (drum roll) ... screen co-ordinates. And how does RectangleToScreen guess that the rectangle you have passed in is actually screen relative and not client relative?
|
|
|
|
|
hi all people
i have a windows form that containes two ComboBoxes, two DataGrids and TextBoxes, i made the necessary to bind all the controls except the second ComboBox (That depends on what is selected in the first ComboBox ), infact i filled the first ComboBox cbCust with the table Customers and i want the second ComboBox cbOrd to be filled with the Orders of the selected Customer. my hole Code is :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace DataBinding
{
public class MasterDetail : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid grdOrders;
private System.Windows.Forms.DataGrid grdOrderDetails;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox cbCust;
private System.Windows.Forms.TextBox txtPhoneNo;
private System.Windows.Forms.TextBox txtFaxNo;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtContact;
private System.ComponentModel.Container components = null;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button btnPrev;
private System.Windows.Forms.Button btnNext;
OleDbConnection cn;
DataSet ds;
private Label label5;
private ComboBox cbOrd;
DataViewManager dsView;
public MasterDetail()
{
InitializeComponent();
cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DataBinding\Northwind.accdb;Persist Security Info=False");
ds = new DataSet("CustOrders");
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM Customers", cn);
da1.TableMappings.Add("Table","Customers");
da1.Fill(ds);
OleDbDataAdapter da2 = new OleDbDataAdapter("SELECT * FROM Orders", cn);
da2.TableMappings.Add("Table","Orders");
da2.Fill(ds);
OleDbDataAdapter da3 = new OleDbDataAdapter("SELECT * FROM [Order Details]", cn);
da3.TableMappings.Add("Table","OrderDetails");
da3.Fill(ds);
System.Data.DataRelation relCustOrd;
System.Data.DataColumn colMaster1;
System.Data.DataColumn colDetail1;
colMaster1 = ds.Tables["Customers"].Columns["CustomerID"];
colDetail1 = ds.Tables["Orders"].Columns["CustomerID"];
relCustOrd = new System.Data.DataRelation("RelCustOrd",colMaster1,colDetail1);
ds.Relations.Add(relCustOrd);
System.Data.DataRelation relOrdDet;
System.Data.DataColumn colMaster2;
System.Data.DataColumn colDetail2;
colMaster2 = ds.Tables["Orders"].Columns["OrderID"];
colDetail2 = ds.Tables["OrderDetails"].Columns["OrderID"];
relOrdDet = new System.Data.DataRelation("RelOrdDet",colMaster2,colDetail2);
ds.Relations.Add(relOrdDet);
dsView = ds.DefaultViewManager;
grdOrders.DataSource = dsView;
grdOrders.DataMember = "Customers.RelCustOrd";
grdOrderDetails.DataSource = dsView;
grdOrderDetails.DataMember = "Customers.RelCustOrd.RelOrdDet";
cbCust.BindingContext = new BindingContext();
cbCust.DataSource = dsView;
cbCust.DisplayMember = "Customers.CompanyName";
cbCust.ValueMember = "Customers.CustomerID";
cbOrd.DataSource = dsView;
cbOrd.DisplayMember = "Customers.RelCustOrd";
cbOrd.ValueMember = "Orders.OrderID";
txtContact.DataBindings.Add("Text",dsView,"Customers.ContactName");
txtPhoneNo.DataBindings.Add("Text",dsView,"Customers.Phone");
txtFaxNo.DataBindings.Add("Text",dsView,"Customers.Fax");
}
private void btnPrev_Click(object sender, System.EventArgs e)
{
if (this.BindingContext[dsView,"Customers"].Position > 0)
{
this.BindingContext[dsView,"Customers"].Position--;
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
CurrencyManager cm = (CurrencyManager)this.BindingContext[dsView,"Customers"];
if (cm.Position < cm.Count - 1)
{
cm.Position++;
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
my question is : How to do to fill the cbOrd ComboBox using the DataBinding?
Thanks in advance.
modified 19-Jun-14 15:31pm.
|
|
|
|
|
sbn1010 wrote: How to do to fill the cbOrd ComboBox using the DataBinding? Bind it when the selection of the other combo changes. There must be some "SelectionChanged" or "SelectedValueChanged" event
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I want to write a program that I would upload an excel file into and analyze the data. Basically, my framework will be read, extract, and output in form of text or pdf.
Where do I begin?
|
|
|
|
|
If you only need to support the new format files (*.xlsx ), then either EPPlus[^] or ClosedXML[^] should allow you to read the file.
If you need to support the older format (*.xls ) as well, then you can use NPOI[^].
If you're writing a web application, avoid using Office Interop; it's not supported in non-interactive programs[^], and will fail in interesting ways.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Further to the answer above, you can always save as csv or xml format and parse it with linq to XML.
OR even better, use ODBC to connect to any excel format and query it with SQL.
|
|
|
|
|
|
I have been trying to change the Category field of a property displayed in a PropertyGrid in runtime.
I know how to change DisplayName and Browseable in runtime and I thought it would be the same way. Just modifying the code. But nope...
The class I want to display in the PropertyGrid is this:
public class Person
{
int age = 10;
[DisplayName("Age")]
[Category("Fact")]
public int Age
{
get { return age; }
}
}
I have a Windows form application containing a PropertyGrid (propertyGrid1) and a button (button1) to switch Person.Age's category between "Fact" and "Info".
public Form1()
{
InitializeComponent();
propertyGrid1.SelectedObject = new Person();
}
private void button1_Click(object sender, EventArgs e)
{
SetCategory();
SetDisplayName();
}
To switch the DisplayName I have this method:
private void SetDisplayName()
{
Person person = propertyGrid1.SelectedObject as Person;
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(person.GetType())["Age"];
DisplayNameAttribute nameAttribute = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
FieldInfo displayName = nameAttribute.GetType().GetField("_displayName", BindingFlags.NonPublic | BindingFlags.Instance);
string name = displayName.GetValue(nameAttribute).ToString() == "Age" ? "The age" : "Age";
displayName.SetValue(nameAttribute, name);
propertyGrid1.SelectedObject = person;
}
This works well.
I "copied" the SetDisplayName method and made a SetCategory method like this:
private void SetCategory()
{
Person person = propertyGrid1.SelectedObject as Person;
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(person.GetType())["Age"];
CategoryAttribute categoryAttribute = (CategoryAttribute)descriptor.Attributes[typeof(CategoryAttribute)];
FieldInfo category = categoryAttribute.GetType().GetField("categoryValue", BindingFlags.NonPublic | BindingFlags.Instance);
string text = category.GetValue(categoryAttribute).ToString() == "Fact" ? "Info" : "Fact";
category.SetValue(categoryAttribute, text);
propertyGrid1.SelectedObject = person;
}
This works all well. When the category.SetValue() has been executed the intelisence of categoryAttribute show that the Category property is "Info" and not "Fact" as previous. Just as I want it.
When the method is finished the category of Person.Age has not been changed and the propertyGrid1 still show "Fact" as category.
I have tried to make any sense of this article which show that it's possible: Dynamic Properties for PropertyGrid[^]
But that example is to big to scope and I get confused.
Can anyone help me?
/Steffe
|
|
|
|
|
At run-time, all attributes are read-only: the can be changed during design-time only.
|
|
|
|
|
Absolutely not!
I can change DisplayName and Browseable attributes in runtime. Also the example article I linked to change many attributes during runtime, even the category which I have problem with.
/Steffe
|
|
|
|
|
Mc_Topaz wrote: This works well. No, it doesn't. It's a dirty hack, and not guaranteed to work. Attributes are meta-data on types, not their instances. The reason for the "Mandatory" comment in the dirty hack is that the propertygrid doesn't expect the category to change, since the definition of the type cannot change.
Mc_Topaz wrote: I have tried to make any sense of this article which show that it's possible Something being possible don't mean it's also a good idea.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I working with a regular Windows Forms application and I would like to read/store user settings from/to an .ini-file. It is very easy to find numerous examples of this through a simple google search, but I can't find one that meets the following requirements:
• Not XML-based.
• The .ini-file should be fairly readable, i.e. contain plain text.
• Arrays of strings and double should be supported. Or even better, any array, struct or class should be supported (but I don't know if that's realistically possible since I want plain text and no serialization).
• Each field in the .ini-file should be easy to read/modify through simple get/set methods. And since the .ini-file is plain text, it is also possible to edit individual settings directly using, for example, Notepad.
Has anyone stumbled across something that meets those requirements?
|
|
|
|
|
an ini file, too my knowledge is never XML. See here[^] If you really want to use ini as standard, make sure to follow it.
From there it is basically just writing a serializer/deserializer to read in or write to the ini file. I would just quickly write on myself as this is not that difficult.
For arrays you can assign a delimeted value to a key and then split on the delimiter.
eg.:
mydoublearray=0.1,0.56,3.141592,54.7
mystringarray="blabla1","blabla2","andsoonandsoforth"
(in this case the "," is the delimeter, but it can be any character or combination of characters. the double pipe "||" is often used as it is rarely or never used in normal strings.)
hope this helps.
|
|
|
|
|
|
How would you want to have that byte[] in a text-file? If you add two structs of the same type, how would it differentiate between those two? Based on the section?
There's always the option of interopping to GetPrivateProfileString, the API that was used to read/write ini-files. The API got deprecated in favor of XML-ini files.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
For an INI file? No and probably not going to find it considering how configuration files are written now-a-days.
For XML files? This is easy to do and you really don't have to write that much code to do it.
|
|
|
|
|
Thanks for your comments. When I read the replies here I get the impression that .ini-files are standardized (by IEEE or something similiar). I didn't know that. What I need is a configuration file (which I intend to give the extension .ini, regardless of whether it meets certain standards or not) that fulfills the requirements in my bulleted list.
|
|
|
|
|
Please don´t. If you call a file *.ini, make sure it follows standards. Same for any other file: bmp, csv, ... whatever.
If anyone else needs to maintain your application, at least he has something to go on.
Nothing prevents you from creating your own standard with a new extension (or an extension without defined standards.)
|
|
|
|
|