|
Use all this...
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;
|
|
|
|
|
Hi Jay,
Can u please explain me why shall I use the Using System.Windows.Forms; in my console application?
However, it worked fine for me. But, take a look at this code:
System.IO.File.Move(@"C:/from.txt", @"C:/to.html");
This one is a short one but workd overwhelmingly fine. We have to use the Move function because, C# doesn't support 'rename' function like C.
Thanx for your help again,
Happy programming and wish u a successful programming career,
Rajdeep.NET
|
|
|
|
|
I thought you are asking for a windows application ??
|
|
|
|
|
Yep, that one line of code is all you need to what you want. I'd ignore some of the poor advice about including numerous irrelevant namespaces and manipulating strings and copying files....
Regards,
Rob Philpott.
|
|
|
|
|
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 Extensionchanges
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
OpenFileDialog1.ShowDialog();
string fl = OpenFileDialog1.FileName;
FileInfo fln = new FileInfo(fl);
string temp = fl.Split('.')[0];
fln.CopyTo(temp + ".html");
}
|
|
|
|
|
The above windows application code show an error:
The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
Why so?
|
|
|
|
|
Its of framework 3.5
remove it if you use 3.0 framework
|
|
|
|
|
Hey Jay,
Sorry man, but I'm using VS.NET 2005 and unfortunately my system is running on .NET framework 2.0. What will I do now?
|
|
|
|
|
Rajdeep.NET wrote: What will I do now?
Follow Rob's advice[^] and don't use all those namespaces! The code you're using isn't using Linq (not available in 2.0 anyway), so just delete the offending line.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
You really dont need LINQ assembly,as it is not used anyway . ..
Just delete any assembly that gives error...
The code is just very simple.. I am unable to understand why you get an error...
|
|
|
|
|
In addition to the advice already received, take a look at the Path.ChangeExtension(pathToFile, newExtension) static method.
You know, if I was looking for a way to change a file extension, one of the first things I would have done is to google for 'change extension (c# OR vb)'. I haven't done that in this case since my ageing brain cells still held the correct information, but why don't you give it a try? Do you want to have a small wager that this solution would be right there at, or very near, the top? If you had done that, it would have saved you 25 minutes, that could be used for productive work.
Any way, others seem to have given you a solution that works, so good luck with whichever way you choose to go.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
How can I access to properties or methods of a control from another forms? Or How can I send information from form to another forms?
Thanks.
|
|
|
|
|
|
One of the best way to pass some value is by overloading the constructor.
For e.g if you want to pass an integer id or something like that from form1 to form2.
you need to do is make a small function on form2 like :
public Form2(int id)
{
InitializeComponent();
this.ID = id;
}
And while opening the form2 in form1 you need to do is
Form2 frm = new Form2(3); //3 can be replaced by any variable.
frm.showdialog();
or
frm.show();
|
|
|
|
|
|
The method that jaypatel512 recommended is OK for value types going from Form1 to Form2 but not recommended for reference types and unworkable for passing values back from Form2 to Form1.
For Form1 to Form2 (giving far more flexibility), use properties and/or methods in Form2.
For Form2 to Form1 use events in Form2 that are subscribed to by Form1.
Example using all the above - I've wired everything up to both form's click events.
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Click += new EventHandler(Form1_Click);
}
void Form1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.FloatEvent += new EventHandler<FloatEventArgs>(form2_FloatEvent);
form2.Int32Property = 32;
form2.SetStringValue("Hello World!");
Console.WriteLine("Int: {0}, String: {1}", form2.Int32Property, form2.GetStringValue());
form2.Show();
}
void form2_FloatEvent(object sender, FloatEventArgs e)
{
Console.WriteLine("Sender: {0}",sender);
Console.WriteLine("Float: {0}", e.FloatValue);
}
}
using System;
using System.Windows.Forms;
public partial class Form2 : Form
{
public event EventHandler<FloatEventArgs> FloatEvent;
private string _StringValue;
public Form2()
{
InitializeComponent();
Click += new EventHandler(Form2_Click);
}
void Form2_Click(object sender, EventArgs e)
{
OnFloatEvent(new FloatEventArgs(Int32Property));
}
public int Int32Property
{
get;
set;
}
public void SetStringValue(string stringValue)
{
_StringValue = stringValue;
}
public string GetStringValue()
{
return _StringValue;
}
protected virtual void OnFloatEvent(FloatEventArgs e)
{
EventHandler<FloatEventArgs> eh = FloatEvent;
if (eh != null)
eh(this, e);
}
}
using System;
public class FloatEventArgs : EventArgs
{
private float _FloatValue;
public FloatEventArgs(float floatValue)
{
_FloatValue = floatValue;
}
public float FloatValue
{
get { return _FloatValue; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
It was exactly my problem!(Form2 to Form1)
Thank you very much.
|
|
|
|
|
No problem
Events (and their use of delegates) are a fundemental part of most modern OOP languages including C#.
Check out my article here[^] for an in depth step by step guide.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi i am building an application in which i want to generate a report. That report consists of data from multiple tables. I tried doing this but when the datagrid is populated with the dataset/datatable the record from second table comes on second row & from third table comes on third row. I am using access database. can someone help me out of this.
Thanks in advance. the code is as shown below.
private void Form1_Load(object sender, EventArgs e)
{
try
{
con = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=e:/ReportTest/ReportTest/ContractSystemDB.mdb");
con.Open();
ds = new DataSet();
dt = new DataTable("ashish");
cmd = new OleDbCommand("select * from CommonData",con);
rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
da = new OleDbDataAdapter("select * from InitialApproval where InitialApproval.PrNo='"+rd.GetString(0)+"'",con);
da.Fill(ds);
da.Dispose();
da1 = new OleDbDataAdapter("select EstimatedVal,FwdDtByPSD from PSDApproval where PSDApproval.PrNo='" + rd.GetString(0) + "'",con);
da1.Fill(ds);
da1.Dispose();
da2 = new OleDbDataAdapter("select POValue,rcd_dtCC,saving from CommonData where CommonData.PrNo='" + rd.GetString(0) + "'", con);
da2.Fill(ds);
da2.Dispose();
}
}
contractSystemDBDataSetBindingSource.DataSource = ds;
MyGrid.DataSource = contractSystemDBDataSetBindingSource.DataSource;
MessageBox.Show("Record Added To Grid View");
}
catch (Exception ex)
{
MessageBox.Show("Error==>" + ex);
}
finally
{
con.Close();
}
}
|
|
|
|
|
Your question is not so clear . .but as much i can understand you want to show all the tables columns in one data grid...
For that you cannot use such a code but u may need to use UNION in your query.
So you need to select all the data in single query using union and then populate data ina single table.
You can google union .. you will get it . ..
It should be something like this :
da1 = new OleDbDataAdapter("select * from InitialApproval where InitialApproval.PrNo='"+rd.GetString(0)+"' UNION select EstimatedVal,FwdDtByPSD from PSDApproval where PSDApproval.PrNo='" + rd.GetString(0) + "' UNION select POValue,rcd_dtCC,saving from CommonData where CommonData.PrNo='" + rd.GetString(0) + "'", con);
da.Fill(ds);
|
|
|
|
|
Hi all
Im facing silly problems abt TabIndex.
Scenario is I have 5 textBox. 2 of them are in a container and other's are inside 3 tableLayoutPanel control. I want to line up or create a serial Taborder only to those all textBoxes.So that I can use key_press event on them.
If you not clear pls let me know
Thanks
|
|
|
|
|
I am not exactly sure what it is that you are asking, but it seems to me that all you need to do is to set the TabOrder for your TextBoxes to the order that you want them accessed in.
For your future reference, it is considered rude to use txtspk in CP forums (abt?, pls?). In this case I don't think it alters the understanding of your problem but it might do in another case. Remember, us old fogeys (who are often the ones that have the answers) mostly avoid posts containing txtspk. So pls dnt do it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I'm loading a listBox with a range (360 to -360), but I want to user to start off at value 0 (what they see). How can I do that? I've tried to use listBox.Items.MoveCurrentToPosition() and listbox.SelectedIndex = x; but neighter have the desired results.
|
|
|
|
|
See what no help and one day of sleep does?
listbox1.ScrollIntoView(value_of_collection);
is what the doctor ordered.
I swear I searched many times on CP, google but never seen one example of someone setting this. Quite strange....and even more strange that I overlooked the method so many times in intellisense/msdn.
Anyways, maybe that will help someone else.
|
|
|
|
|
Gawwwwd.
So I did that example at work a few days ago. Now I come home and work on my project and what do you know, it ain't working. Before I jump off a cliff I decided to look into it. 10,000 compiles and 10,000 "come on man!" later, and I finally got it. I mean, it's so irritating and funny when some little dumb thing like this happen. Now i'm certain I tried this method before posting my original post, but didn't work...yadda yadda.
drumroll please...
The reason is that I was using a tab container and this listBox was on the second tab, NOT in the VIEW of the application when it loaded.
So I ended up responding to the Tab events something like this:
private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TabControl tc = sender as TabControl;
if (tc.SelectedIndex == 1 && selectedIndexTracker !=1)
{
selectedIndexTracker = 1;
angleListBox.ScrollIntoView(15);
}
}
|
|
|
|