|
Hi friends, i got a problem with connecting data of controls to a database at runtime.
First, i wanted to create "n" number of textbox controls at runtime. And it was successful.
Secondly, i wanted to store content or data of the textboxes to my database, the problem is since the controls of Textbox are going to be created at runtime, how can i represent the value(data) of those textboxes at runtime ?
Example: if i need to create 3(n == 3)textboxes and wanted to store their data into my table.
Insert into table1 values(text1.text, text2.text, text3.text);
if( n == 5)
Insert into table1 values(text1.text, text2.text, text3.text, text4.text, text5.text);
Girmay
|
|
|
|
|
What is the criteria which governs the number of textboxes? What is the structure of table1?
जय हिंद
|
|
|
|
|
I am getting the following message box whenever I try to debug the code.
“The following module was built either with optimization enabled or without debug information:”
“To debug this module, change its project build configuration to Debug mode.
To suppress this message, disable the ‘Warn if no user code on launch’ debugger option”
I have built the entire code in Debug mode and no where I have enabled the optimization setting.
I am using Microsoft Visual Studio 2008.
I am using the C# .NET for the very first time please help me out in this.
|
|
|
|
|
Can you see .pdb files for your assemblies in the bin/Debug directory? Does cleaning and rebuilding in Debug mode help?
|
|
|
|
|
hi,
i am using to retrive the value from listbox items as
foreach (var obj in listbox.Items)
{
?????????????????
}
but i have no idea what should be in foreach body.
thanks
|
|
|
|
|
It depends what you want to do with the item.
Unlike a ListViewItem , a list box item is just an object, whose ToString() method is called to render its text in the list box.
/ravi
|
|
|
|
|
zeeShan, I hope this helps.
It depends on what you want to do with your items. They are usually cast at some point. Consider this code. When something is selected in listBox1, it copies all of the contents into listBox2:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (string item in listBox1.Items)
{
listBox2.Items.Add(item);
}
}
|
|
|
|
|
Here i provide you source code wish that help you :
for example if you want to calculate all values of liste item .
Dim sum As Integer
For Each item As String In data.ListBox1.Items
sum += Double.Parse(item)
Next
textbox1.text = sum
It will show total value of Items
|
|
|
|
|
Hi all.
I can not use my controls from another class file.
The scenario is:
I have 1 form "Form1" in which there have many controls like combobox, textbox, listbox.
I have added a class file "Class1.cs" where I have using all "System.windows" namespaces and "System.Data.SQLClient" also.
But in the class file when I want to access or manipulate the controls of that form, the controls shows the error
"The name does not exist in the current context".
where I have changed all modifier property of those controls "Public". Where is the problem?
If it i impossible then how can I solve it?
what else should I do?
please help me
Thanks in advance
modified on Monday, May 18, 2009 12:59 AM
|
|
|
|
|
Class1 needs a reference to the instance of Form1 in order to manipulate that instance's controls (and other public properties and methods).
/ravi
|
|
|
|
|
How can I pass reference to the class1.cs file?
|
|
|
|
|
You don't pass the reference to a file, you pass it to the instance of the consuming class. With all due respect, I think you may be better off first understanding the basic concepts about programming before attempting this task.
/ravi
|
|
|
|
|
okay thanks. I will try read.
But I have tried to create instance to the class file. But it does not recognize the form object.
I dont know whether you can get me or not letme clear again.
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.SqlClient;
using ourLibrary;
namespace MonitoringCheckList2009
{
public partial class BaseForm : Form
{
}
}
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ourLibrary
{
public class LibraryClass
{
public void ShowLC(string dbTable, Control LstBox)
{
in form1.
}
}
}
If you dont understand pls let me know
Thanks
|
|
|
|
|
First of all, ShowLC() should accept a ListBox as its 2nd parameter, not a Control (unless you really want to pass a Control ).
From somewhere in your BaseForm do the following:
LibraryClass lc = new LibraryClass();
lc.ShowLC ("some string", this.listBox1);
/ravi
|
|
|
|
|
thanks a lot....
This is the ans I am finding.
Np i will read more.
|
|
|
|
|
Ravi has given you a solution that will work, but I don't believe it's the best or recommended way. Your Class1 should not be reliant on other objects to do it's stuff, so passing an object reference (a form, a control etc) in the constructor or elsewhere is not a good idea.
If the controls on Form1 need to be manipulated, it should be done from Form1 and nowhere else. If it needs to be in response to activity in Class1, then Class1 should raise relevant events and Form1 should subscribe to those and update the controls, play a fanfare or whatever.
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)
|
|
|
|
|
Thanks Dev But by useing Ravi's advice I can use my controls from anywhere I want. I just need to pass those controls by method, therest of the job will be done by that class1.
Isn't it helpfull?
|
|
|
|
|
Class1 is doing the job with controls which it doesn't own - a far from ideal situation. It's a quick and dirty solution, but I advise you to avoid it.
An event driven system is much better and not difficult. Simple example below:
using System;
public class Class1
{
public event EventHandler<MyEventArgs> MyEvent;
public void PerformMyMethod(string item)
{
OnMyEvent(new MyEventArgs(item));
}
protected virtual void OnMyEvent(MyEventArgs e)
{
EventHandler<MyEventArgs> eh = MyEvent;
if (eh != null)
eh(this, e);
}
}
public class MyEventArgs : EventArgs
{
private string _MyString;
public MyEventArgs(string myString)
{
_MyString = myString;
}
public String MyString
{
get { return _MyString; }
}
}
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
Class1 class1;
public Form1()
{
InitializeComponent();
class1 = new Class1();
class1.MyEvent += new EventHandler<MyEventArgs>(class1_MyEvent);
class1.PerformMyMethod("Hello World");
}
void class1_MyEvent(object sender, MyEventArgs e)
{
MessageBox.Show(string.Format(
"{0} from {1}!", e.MyString, sender));
}
}
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)
|
|
|
|
|
Thanks Deve...
I am totally new in C# but I have already develop a software for my office :P
With those poor logics. Now I am trying to read more and use best solution.
I am trying to understand your code.
Thanks for your effort.
|
|
|
|
|
Have a look at my article Events Made Simple[^] - it explains each line and builds step by step.
If you need more clarification, feel free to post back here
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,
does anybody know of any information that suggests which version of the .NET framework is most popular?
We are looking to develop an application on .NET 3.5, but which version is most commonly installed?
thanks
Bluetooth Marketing
Bluetooth Advertising
|
|
|
|
|
|
According to my knowledge Framework version 2.0 is the best and stable. After all version 3.0 and 3.5 are extension of 2.0.
A DATAPOST COMPUTER CENTRE
(K.V Prajapati)
|
|
|
|
|
Be that as it may, how many systems have those but not 1.1?
|
|
|
|
|
Of course you are right. I meant the popular one.
A DATAPOST COMPUTER CENTRE
(K.V Prajapati)
|
|
|
|