|
In a slight bending of the Hole Good Code Rules, in favour of simplicity, I am implementing a Grouping attribute (type string) on a UI class of mine, the ExportLine. It can have one of three constant values, or the name of a grouping field. What is the best way to implement the contant values? I'm thinking static properties on my ExportLine. Given what I'm doing is not really good anyway, is the properties approach a good one?
|
|
|
|
|
I'm not quite sure I follow you, but maybe readonly fields would be better?
|
|
|
|
|
I'm not sure if better, but definitely an option worth comparing to mine. A get only property, and a read only field are pretty similar if the are only read inside their class.
|
|
|
|
|
I doubt you could argue that the property is better either. Unless you want it to be virtual ?
A readonly property that could easily be replaced by a readonly field may wind up in the "coding horrors" forum.
|
|
|
|
|
I've moved the static properties to a class specifically to hold them. It has no code, so I think the difference is moot now.
|
|
|
|
|
HI,
i've got a problem.
i'm canginng the computer Resolution so it fit my APP (Like games do at when they start)
and rechanging back to the old Resolution when the APP closes.
So far So Good, but i don't know how to save the icon's layout
when i change the Resolution back, i'd like to save the layout so the user gets the screen he had
before working with APP
THANKS
Have Fun
Never forget it
|
|
|
|
|
|
If clicking the button submits a form (vs. executing some JavaScript), you can use a WebResourceProvider [^] to do your bidding.
/ravi
|
|
|
|
|
Hi
I want to access files which are on a network share in another server.
When I try to access (manually, not through C#) the other server I get the window of username and password and I can access the files.
I want through C# to read the files which are in this share and to specify within C# the username and password for accessing the share.
Any ideas ?
Clint
|
|
|
|
|
|
hi ,
i am a newbie to C# programmin , reading it from a book(C# Software Solutions. Foundations of Software Design author John Lewis). the other day i was trying to solve a question given in the book wherein , i have to create a program that reads an arbitrary number of integers (in range of 0-50 inclusive) and counts how many occurences of each are entered, once all the inputs are processed , the output should print the values (with number of occurences) that were entered one or more times.
finally when the program is working , i have to try the same in the range of (-25 to 25
can anyone help me with the coding of this program..
thanks
|
|
|
|
|
harrysc74 wrote: can anyone help me with the coding of this program..
What part of the program are you having trouble with? What code have you written so far?
No one is going to do your homework and write the program for you. If you want help with a specific problem, post your code and someone might be able to asist.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
harrysc74 wrote: can anyone help me with the coding of this program..
By definition, you have to start coding first, then someone can help you with it. Otherwise it would be 'writing the code for you', not 'helping you with the coding'.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I want to send a array of string (string[] f) wint
Byte[] var = Encoding.ASCII.GetBytes(f);
I can't do it on this way.
What i can use to do this?
|
|
|
|
|
Loop through the strings in the array. Call Encoding.ASCII.GetBytes() for each element in the array.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
|
Lets say I have two forms (Form1 and Form2).
On Form1 there is a listbox that holds phone numbers.
On Form2 there is two textboxes where you enter a phonenumber and a description.
On Form1 you click a button and it opens Form2 to enter the information. So how do you take the information that is entered on Form2 and add it to the listbox on Form1?
|
|
|
|
|
There are several ways to do this. I'll give you the "easiest" (and least elegant):- Make the
Form1.myListBox member public.
- Pass a reference of the
Form1 instance to Form2 .
- In
Form2 's OnOKButtonClicked() handler, add the required entry to myListBox . /ravi
|
|
|
|
|
I'm still lost on this. I made listBox1 public.
Now how exactly am I going to do this? I need to transfer a textbox from Form2 back to Form1.
|
|
|
|
|
Jacob Dixon wrote: I need to transfer a textbox from Form2 back to Form1.
No. You need to copy data from one control (a textbox) to another (a listbox). For example:
theListBox.Items.Add (theTextBox.Text);
It seems you may have taken on a task that's (currently) a bit out of your reach. I recommend that you come up to speed on the basics of WinForms before continuing.
/ravi
|
|
|
|
|
Yea i know.. I haven't continued, but I'm ordering two books and going to read some more.
|
|
|
|
|
You can use Ravi's solution. However, that will make some data off your listbox, public.
I suggest to have Form2 with a property of type string,which gets and sets the data. in your case the set is mostly important. From Form1...you only need to set the property. From form2 just set the given value to the textbox.
I think its a little safer.
Regards
Kev.
|
|
|
|
|
Yea... uhmm I'm still a little confused... do you have an example or a website with a tutorial?
|
|
|
|
|
Hi Friends,
May be this will help you guys to help me .
I have in the form a textbox,a enter button and datagrid.
I want to enter data into my DB Table named "Self" on the click of button "Enter".
Till there its working fine.
Now on form load am trying to display the contents in my database (for simlicity i have only one coloumn in my database:"Name") in a datagrid.
The problem am facing is in writting that part of the code.
Shown below is my code.Please correct me.
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb";
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select * from Self";
cmd.Connection = con;
OleDbDataAdapter adap = new OleDbDataAdapter();
adap.SelectCommand = cmd;
DataSet ds = new DataSet();
adap.Fill(ds);
}
Now i will display my entire code if it might help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Odbc;
using System.IO;
namespace My_self_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb";
con.Open();
OleDbCommand cmdObj = new OleDbCommand();
cmdObj.CommandText = "Insert into Self(Name) values ('" + txtName.Text + "')";
cmdObj.Connection = con;
cmdObj.ExecuteNonQuery();
}
private void txtDisplay_Click(object sender, EventArgs e)
{
}
private void gridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb";
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select * from Self";
cmd.Connection = con;
OleDbDataAdapter adap = new OleDbDataAdapter();
adap.SelectCommand = cmd;
DataSet ds = new DataSet();
adap.Fill(ds);
}
}
}
Thanking you
|
|
|
|
|
I have written like this and this works:
dbConnetion1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db.mdb";
dbConnetion1.Open();
oleDbCommand1.CommandText = "select * from Name";
oleDbCommand1.CommandType = CommandType.Text;
oleDbCommand1.Connection = dbConnetion1;
oleDbCommand1.ExecuteNonQuery();
oleDbDataAdapter1.SelectCommand = oleDbCommand1;
DataTable table1 = new DataTable();
oleDbDataAdapter1.Fill(table1);
dataGridView1.DataSource = table1;
//or this one
DataSet dataset1 = new DataSet();
oleDbDataAdapter1.Fill(dataset1, "Name");
dataGridView2.DataSource = dataset1;
dataGridView2.DataMember = "Name";
dbConnetion1.Close();
Sourie
|
|
|
|