|
Then you can use 00000.00 as Mask . and it will be decimal.
|
|
|
|
|
but I want to use the numeric text box control...it's soo much easier and faster and does what I want. Just pop it in the form and your done..I have tons of them...
I also tried another piece of code and I got the same exact error...so it must be a form setting of some sort.
Thanks
|
|
|
|
|
Hi all!
I am trying to create an application for Pocket PC 2003 using C#, to send an SMS by connecting a built-in GSM modem through the USB port. I have found a library called SMSLib, which contains all the functions for sending n receiving an SMS through a GSM modem connected via USB.
I wrote a desktop appln. initially, to check whether the library works. It worked out successfully on the desktop app.
Now i have written the same code in a PPC2003 C# project, but it is not working.
The port to which i have connected the modem is not getting detected on the emulator. Because of this it is givin me an IOException.
Plz. can sumone tel me wat i should do, so that the port gets detected on the emulator???????????
N yes, I have also tried using ActiveSync, but No Luck!! May be it is not useful, or may be I dont know how to use it.
PLEASE help me out... Plz....
Thank You!
|
|
|
|
|
You should post your question in Mobile Developement [^]board and there maybe someone can give you any right direction.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hello,
I'm having trouble with this code. I have 3 files:
program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace keyFortress
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
lView mylView = new lView();
mylView.GetData();
mylView.LoadList();
}
}
}
lView.cs
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.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;
namespace keyFortress
{
class lView
{
public DataSet _DataSet;
public SqlCeConnection _Conn;
public SqlCeDataAdapter _DataAdapterTitles;
public void GetData()
{
string strConn = @"Data Source = |DataDirectory|\psw01.sdf;Password=******";
try
{
_Conn = new SqlCeConnection(strConn);
string strSQL = "SELECT username, "
+ "password "
+ "FROM tbl_data "
+ "ORDER BY username";
_DataSet = new DataSet();
_DataAdapterTitles = new SqlCeDataAdapter(strSQL, _Conn);
_DataAdapterTitles.Fill(_DataSet, "tbl_data");
}
catch (Exception ex)
{
string msg = ex.Message.ToString();
MessageBox.Show(msg, "Unable to retrieve data.",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
public void LoadList()
{
DataTable dtable = _DataSet.Tables["tbl_data"];
listView1.Items.Clear();
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
if (drow.RowState != DataRowState.Deleted)
{
ListViewItem lvi = new ListViewItem(drow["username"].ToString());
lvi.SubItems.Add(drow["password"].ToString());
listView1.Items.Add(lvi);
}
}
}
}
}
Form1.Designer.cs
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.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;
namespace keyFortress
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
this.listView1.Location = new System.Drawing.Point(12, 28);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(131, 167);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = View.Details;
this.listView1.LabelEdit = true;
this.listView1.AllowColumnReorder = true;
this.listView1.CheckBoxes = false;
this.listView1.FullRowSelect = true;
this.listView1.MultiSelect = false;
this.listView1.GridLines = false;
this.listView1.Columns.Add("username", -2, HorizontalAlignment.Left);
this.listView1.Columns.Add("password", -2, HorizontalAlignment.Left);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 264);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView1;
}
}
When I compile this I get the following error:
The name 'listView1' does not exist in the current context, this appears twice:
listView1.Items.Clear();
listView1.Items.Add(lvi);
Can anybody tell what the problems is?
Many thanks
modified on Wednesday, March 25, 2009 10:52 AM
|
|
|
|
|
The problem is that you have never instancized (whatever you spell this word :P) it.
In order to use the listView1, you have to call the InitializeComponents() function, do this in the constructor of lView:
public lView()
{
InitializeComponents();
{
And it should work.
|
|
|
|
|
Thanks,
I've ammended the code so that it looks like:
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.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;
namespace keyFortress
{
class lView
{
public DataSet _DataSet;
public SqlCeConnection _Conn;
public SqlCeDataAdapter _DataAdapterTitles;
public lView()
{
InitializeComponent();
}
public void GetData()
{
string strConn = @"Data Source = |DataDirectory|\psw01.sdf;Password=******";
try
{
_Conn = new SqlCeConnection(strConn);
string strSQL = "SELECT username, "
+ "password "
+ "FROM tbl_data "
+ "ORDER BY username";
_DataSet = new DataSet();
_DataAdapterTitles = new SqlCeDataAdapter(strSQL, _Conn);
_DataAdapterTitles.Fill(_DataSet, "tbl_data");
}
catch (Exception ex)
{
string msg = ex.Message.ToString();
MessageBox.Show(msg, "Unable to retrieve data.",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
public void LoadList()
{
DataTable dtable = _DataSet.Tables["tbl_data"];
listView1.Items.Clear();
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
if (drow.RowState != DataRowState.Deleted)
{
ListViewItem lvi = new ListViewItem(drow["username"].ToString());
lvi.SubItems.Add(drow["password"].ToString());
listView1.Items.Add(lvi);
}
}
}
}
}
However this gives a different error (orginal 2 errors still remain)
The name 'InitializeComponent' does not exist in the current context
|
|
|
|
|
listView1 is defined on the form, not in lView. Form1 and lView are two separate classes, and neither knows how to reach the other one.
1a) Instead of creating mylView in the Main() method, create it inside the form
OR
1b) Change the declaration of listView1 from private to public in the Form1 code
(The first option is preferable, as the second violates standard practices)
THEN
2) Change LoadList to accept a ListView as a parameter, and pass listView1 into it.
Example:
public void LoadList(ListView myListView)
{
...
}
In the Form1 constructor:
lView mylView = new lView();
mylView.GetData();
mylView.LoadList(listView1);
|
|
|
|
|
Thanks. I'm beginning to understand. I think I've implemented the changes you suggested. However the orginal errors remain.
Here is the code that I now have:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace keyFortress
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
lView.cs
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.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;
namespace keyFortress
{
class lView
{
public DataSet _DataSet;
public SqlCeConnection _Conn;
public SqlCeDataAdapter _DataAdapterTitles;
public void GetData()
{
string strConn = @"Data Source = |DataDirectory|\psw01.sdf;Password=******";
try
{
_Conn = new SqlCeConnection(strConn);
string strSQL = "SELECT username, "
+ "password "
+ "FROM tbl_data "
+ "ORDER BY username";
_DataSet = new DataSet();
_DataAdapterTitles = new SqlCeDataAdapter(strSQL, _Conn);
_DataAdapterTitles.Fill(_DataSet, "tbl_data");
}
catch (Exception ex)
{
string msg = ex.Message.ToString();
MessageBox.Show(msg, "Unable to retrieve data.",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
public void LoadList(ListView myListView)
{
DataTable dtable = _DataSet.Tables["tbl_data"];
listView1.Items.Clear();
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
if (drow.RowState != DataRowState.Deleted)
{
ListViewItem lvi = new ListViewItem(drow["username"].ToString());
lvi.SubItems.Add(drow["password"].ToString());
listView1.Items.Add(lvi);
}
}
}
}
}
Form1.cs
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;
namespace keyFortress
{
public partial class Form1 : Form
{
public Form1()
{
lView mylView = new lView();
mylView.GetData();
mylView.LoadList(listView1);
}
lView mylView = new lView();
}
}
Form1.Designer.cs
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.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;
namespace keyFortress
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
this.listView1.Location = new System.Drawing.Point(12, 28);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(131, 167);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = View.Details;
this.listView1.LabelEdit = true;
this.listView1.AllowColumnReorder = true;
this.listView1.CheckBoxes = false;
this.listView1.FullRowSelect = true;
this.listView1.MultiSelect = false;
this.listView1.GridLines = false;
this.listView1.Columns.Add("username", -2, HorizontalAlignment.Left);
this.listView1.Columns.Add("password", -2, HorizontalAlignment.Left);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 264);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView1;
}
}
|
|
|
|
|
Almost there... Two things:
1) Your Form1 constructor should have already had a call to InitializeComponent();. You need to keep that in there, or it won't actually create any of the controls. That should be the first line in the constructor. The way the designer works is that it puts all of the code in InitializeComponent so you can just push it out of the way when you're writing your own code.
2) I'm guessing you're new to function parameters in general. No problem. We all were at one point or another (Ah, memories)...
Instead of just giving you the answer, let me explain how it works...
Say you're making a function to add two numbers together. You want to call it like this:
int dogs = 5;
int cats = 2;
int animals = AddNumbers(dogs, cats);
But one of the main reasons for functions is that they're reusable. Somewhere else in your program, you might want to do this:
int boys = 6;
int girls = 3;
int children = AddNumbers(boys, girls);
Now, when you actually make the AddNumbers function, it doesn't know what's being passed into it. All it needs to know is how to take any two numbers and add them together. So we implement it like this:
public int AddNumbers(int a, int b)
{
return a + b;
}
So what are 'a' and 'b'? Anything. In the first case, 'a' represents 'dogs' and 'b' represents 'cats'. In the second, 'a' represents 'boys' and 'b' represents 'girls'. The function doesn't know what boys and girls or cats and dogs are. It just uses 'a' and 'b' to represent 'whatever is being added'.
So back to your current problem... Instead of adding two numbers together, we're putting data into a ListView. We're passing listView1 to the function, but the function doesn't know what listView1 is. It only knows the name of its parameter, which in this case represents the same thing. The method declaration could just as easily have been:
public void LoadList(ListView a)
See where I'm going with this?
|
|
|
|
|
Ah I see, I've change the Loadlist() method so that instead of working on myListView it uses the following:
public void LoadList(ListView listView1)
It now works as expected.
I appreciate you taking the time to help and explain.
|
|
|
|
|
Sorry, one other quick question some code seems to disappears when I alter the controls, for example:
Before:
this.listView1.Location = new System.Drawing.Point(12, 28);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(131, 167);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = View.Details;
this.listView1.LabelEdit = true;
this.listView1.AllowColumnReorder = true;
this.listView1.CheckBoxes = false;
this.listView1.FullRowSelect = true;
this.listView1.MultiSelect = false;
this.listView1.GridLines = false;
this.listView1.Columns.Add("username", -2, HorizontalAlignment.Left);
this.listView1.Columns.Add("password", -2, HorizontalAlignment.Left);
If I then add a button the code changes to this:
this.listView1.AllowColumnReorder = true;
this.listView1.FullRowSelect = true;
this.listView1.LabelEdit = true;
this.listView1.Location = new System.Drawing.Point(12, 28);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(131, 167);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
As it chops the bottom of the code off the programs no longer works? Is this happening by design?
|
|
|
|
|
The InitializeComponent() method is what the designer creates... It's a translation of everything you've done via point-and-click. Whenever you make any changes that way, it recreates the method.
Any initialization code YOU write should instead be in the Form1 constructor, right after the call to that method (Or somewhere else, but not in InitializeComponent).
I believe there's even a comment at the beginning reading:
So yes, this is by design.
|
|
|
|
|
I'm student In thamar university
|
|
|
|
|
|
Thanks a lot
|
|
|
|
|
khalid altahree wrote: I'm student In thamar university
Not for long any more.
Seriously we are not here to do your homework.
Start programing, read a book (or ten), google, ask your teacher and if you get stuck after all that on a particular problem post your question here, with code, error and behavior.
Nobody is just going to create this program for you (or give it if they already have it)
|
|
|
|
|
It was very stupid question. sorry for that .. and Thank you so much for replying and explaining me how things work here.
|
|
|
|
|
khalid altahree wrote: I'm student In thamar university
And you will probably fail at it.
|
|
|
|
|
No! I got the full mark in that project .. it was very stupid question, thank you for replying.
|
|
|
|
|
The university you go to should be informed immediately. What makes you think you deserve a qualification based upon somebody else's work?
|
|
|
|
|
You know I got excellent with honor afterwards Then I did my higher education in Germany.
I know how stupid my question was .. Thank you for replying.
|
|
|
|
|
I'm a software developer in Rome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You are very kind
Thanx
|
|
|
|
|
|