1,469 Posted Topics

Member Avatar for akshaya kochare

Subscribe to KeyPress event hander of textBox control and use this code inside of it: [CODE] Private Sub textBox1_KeyPress(sender As Object, e As KeyPressEventArgs) 'allows backspace key If e.KeyChar <> ControlChars.Back Then 'allows just number keys e.Handled = Not Char.IsNumber(e.KeyChar) End If End Sub [/CODE]

Member Avatar for Mitja Bonca
0
228
Member Avatar for FELIGO

Hi, check [URL="http://stackoverflow.com/questions/232395/how-do-i-sort-a-two-dimensional-array-in-c"]here[/URL] for solution.

Member Avatar for thines01
0
2K
Member Avatar for noobprogrammerr

Try to do this way: [CODE] string[] arrString = { "a", "b", "c" }; List<String> lstString = new List<string>(arrString); [/CODE] when your method needs to retun a List<T> then you do: [CODE] //...... private List<string> GetData() { string[] arrString = { "a", "b", "c" }; return new List<string<(arrString); } [/CODE]

Member Avatar for thines01
0
280
Member Avatar for nerkla

like: [CODE] Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Dim fileName As String = comboBox1.SelectedItem.ToString() textBox1.Text = [String].Format("{0}{1}{2}", "C:\files", fileName, ".txt") End Sub [/CODE]

Member Avatar for nerkla
0
146
Member Avatar for Sokh

Your program can only rely on the computer time you are using (to the time your computer is set to). If you really want to get tan actual curent time (your local or some else time), you will have to connect to an internet and get the time from server. …

Member Avatar for Sokh
0
274
Member Avatar for morfious90

I would do as Momerat h said. Create a class of one Element, and then create a List<T> which will hold the list of all elements. Class will hold data (properties) specific for each element (Name, Shortname, Number, (and position maybe, because the periodic table is not simetric - for …

Member Avatar for MORFIOUS
0
2K
Member Avatar for csharp_user

If you have only simple strings as items in comboBOx then you can do: [CODE] //in combobox_selectedIndexChanged event: if(comboBox1.SelectedItem.ToString() == "item 1") new Form2().Show(); else if(comboBox1.SelectedItem.ToString() == "item 2") new Form3().Show(); else if(comboBox1.SelectedItem.ToString() == "item 3") new Form4().Show(); [/CODE]

Member Avatar for csharp_user
0
163
Member Avatar for vegaseat

You can convert DateTime value to an integer, to get the hour and minutes seperated values. And then use them to compare to the hours which defines to when you say good morning and afternoon. [CODE] DateTime time = DateTime.Now; int hour = time.Hour; int minutes=time.Minute; if (hour <= 12) …

Member Avatar for Tsawm
0
970
Member Avatar for pennywise134

I did your homework, and you owe me a beer: [CODE] public partial class Form1 : Form { int[] scores; public Form1() { InitializeComponent(); TextBox[] tbs = new TextBox[] { textBox2, textBox3, textBox4 }; foreach (TextBox tb in tbs) tb.Enabled = false; textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress); textBox1.Focus(); } private void …

Member Avatar for D19ERY
0
704
Member Avatar for Zarl

To the original post of this thread: when done with the project, go to upper drop down menu, select Build > Publsh YourApplicationName. This will create a setup.exr file. You can find it on a specified path. To the last question: Sorry, we have to follow the forum`s rules, and …

Member Avatar for thines01
0
84
Member Avatar for c#learner

I have added a textBox and a button controls on the form. Into textBox you write the number of days in month and press the button: [CODE] private void button1_Click(object sender, EventArgs e) { int noOfDays = int.Parse(textBox1.Text); DateTime today = DateTime.Today; int tempDays; List<string> listOfMonths = new List<string>(); for …

Member Avatar for nick.crane
0
100
Member Avatar for existinglady

You can use String.Join() method if you data are in stirng array: [CODE] string[] arr = { "a", "b", "c" }; string str = String.Join(" ", arr); //copy str to textBox.Text property [/CODE] In case if your array is not string array ,you can do it like this: [CODE] double[] …

Member Avatar for existinglady
0
2K
Member Avatar for PutingPanday

Simple way: [CODE] Private Sub button1_Click(sender As Object, e As EventArgs) Dim item As String = txtbuttons.text Dim tbs As TextBox() = {txtAns, txtAns2, txtAns3, txtAns4, txtAns5} For i As Integer = 0 To item.Length - 1 tbs(i).Text = item(i).ToString() Next End Sub [/CODE]

Member Avatar for PutingPanday
0
210
Member Avatar for visored23

You cannot set DataReader as a binding source to any control. Instead, you should use DataAdapter class. [CODE] //... progress.Value = 40; OleDbConnection conn = new OleDbConnection("connString"); DataTable table = new DataTable(); //can be a class variable too. OleDbDataAdapter da = new OleDbDataAdapter("SELECT ID, Status FROM AH01", conn); da.Fill(table); GridView1.DataSource …

Member Avatar for visored23
0
194
Member Avatar for bukk123

simpliest way: [CODE] Dim data As String() = comboBox1.SelectedItem.ToString() textBox1.Text = data(0) textBox2.Text = data(1) [/CODE]

Member Avatar for Phasma
0
589
Member Avatar for ibpet11

Just one thing to add here: Why you dont use a FULL parametreized query? This means that you add parameters for all the values, like you did for StartDate and EndDate.

Member Avatar for Mitja Bonca
0
114
Member Avatar for maggoteer

You cannot have like: [CODE]If Mydata(0).Read = Label2.Text Then[/CODE] This does nothing. Read is a method, and not a property. SqlDataReader class cannot be compared with some string. What you can do, is to compare an actual reader with it, like: [CODE] If Mydata(0).Read() = Label2.Text Then Button5.Enabled = False …

Member Avatar for Mitja Bonca
0
163
Member Avatar for Ehtesham Siddiq

The best approach would be to create a new Thread (or using Backgroundworker - which is almost the same as creating new thread), and put the time consuming code (in your case this is work with database and generating excel file from the data), and put the progressBar on the …

Member Avatar for Mitja Bonca
0
832
Member Avatar for abc_123abc

You didnt say exactly where from, so I will assume from database. You can write an sql query that will look like: [CODE] Dim sqlQuery As String = "SELECT * FROM MyTable WHERE DateColumn >= @param1 AND DateColumn <= @param2" 'by using sqlcommand you then define parameters: cmd.Parameters.Add("@param1", SqlDbType.DateTime).Value = …

Member Avatar for gd740
0
4K
Member Avatar for mihirpatel12

So you want to display one one item? If one, which one? If more, you better use Listobx control.

Member Avatar for Pgmer
0
144
Member Avatar for baladeveloper

Hi, check this out: [CODE] private void viewSnapShotButton_Click(object sender, EventArgs e) { string connectionString = ConfigurationManager.AppSettings["myCconnectionSstring"]; string queryString = ConfigurationManager.AppSettings["MyQueryString"]; SqlConnection connection = new SqlConnection(connectionString); try { connection.Open(); SqlCommand command = new SqlCommand(queryString, connection); byte[] image = (byte[])command.ExecuteScalar(); MemoryStream ms1 = new MemoryStream(image); pictureBox1.Image = Bitmap.FromStream (ms1); ms1.Close(); } finally …

Member Avatar for baladeveloper
0
148
Member Avatar for virusisfound

simpliest way to convert stirng to byte[] is: [CODE] string str = "some text"; byte[] byteArr = Encoding.UTF8.GetBytes(str); [/CODE] in your case it seems that you dont have type of byte in the database, but its varchar, so you can only read it to string, like: [CODE] string str = …

Member Avatar for Mitja Bonca
0
219
Member Avatar for AT--O

Exactly. Close() method calls a Dispose() method, which terminates and removes the instance of an object. This means that it does no exist any longer. To use a Show() method again, you have to create a new instance of an object. Alternative: Instead of calling Close or Dispose methods, better …

Member Avatar for AT--O
0
1K
Member Avatar for Plantcode

Maybe you have to write the full path to the database: [CODE]"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Folder1\Folder2\LocalAccess40.mdb"[/CODE]

Member Avatar for Plantcode
0
252
Member Avatar for euclid135

A must? Why? This is a nonsense. All time consuming code must me on seperated thread, otherwise your UI will freeze (like it is now).

Member Avatar for euclid135
0
155
Member Avatar for ChaseRLewis

So send a reference into that class. This way will be available here and there. As long as you dont do a NEW referenve it "old" one always has the "old2 data holding inside. Example: [CODE] class Class1 { private List<string> list = new List<string>(); //this is now our varaible …

Member Avatar for ChaseRLewis
0
258
Member Avatar for gsting_88

Hi, check here: [CODE] public bool IsValidEmail(string emailAddress) { if (string.IsNullOrEmpty(emailAddress)) { return false; } string _emailPattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; return new Regex(_emailPattern).Match(_emailPattern).Success; } //OR: private bool ValidatingEmail(string inputEmail) { string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; Regex re = new Regex(strRegex); if (re.IsMatch(inputEmail)) return (true); else return (false); } …

Member Avatar for Mitja Bonca
0
302
Member Avatar for Noob_in_progs
Member Avatar for Noob_in_progs
0
415
Member Avatar for vatwindad

This way if you have an integer array (ar any other then string array): [CODE] int[] array = { 1, 2, 3, 4, 5 }; MessageBox.Show(String.Join("\n", array.Select(s => s.ToString()).ToArray())); [/CODE]

Member Avatar for Mitja Bonca
0
71
Member Avatar for anerchy

Exactly, all parameters in the insert statment must be seperared by comma. But you can use a better approach with parametereized query: [CODE] cmdtext = "insert into tblSTUDENT(FULLNAME, PARENTNAME, AGE) VALUES(@p1, @p2, @'3)"; cmdtext.Parameters.Add("@p1", SqlDbType.VarChar, 50).Value = txtStudentName.Text; cmdtext.Parameters.Add("@p2", SqlDbType.VarChar, 50).Value = txtParentName.Text; cmdtext.Parameters.Add("@p3", SqlDbType.VarChar, 50).Value = txtAgr.Text; [/CODE] Parameters …

Member Avatar for anerchy
0
246
Member Avatar for markdean.expres

To do the focus and highligh all the text inside ot it: [CODE] texrBox1.Focus() texrBox1.SelectionStart = 0 texrBox1.SelectionLength = textBox1.Text.Lenght [/CODE]

Member Avatar for markdean.expres
0
276
Member Avatar for rrr12345

You have to subscribe to this event. It means: [CODE] public MainForm() { //button click event subscribtion: //if there is no this line of code, event will NOT rise!! button1_Click += new EventHandler(button1_Click); } //actualy event (it will be rised when button clicked: private void button1_Click(object sender, EventArgs) { } …

Member Avatar for Mitja Bonca
0
85
Member Avatar for markdean.expres

try with: [CODE]listBox1.Font = New Font("Arial", 10, FontStyle.Regular)[/CODE]

Member Avatar for Reverend Jim
0
678
Member Avatar for MARKAND911

Return type can be simply an object. Then if the other class where you will receive it, you use GetType method: [CODE] public class Program { void YourMethod() //can be main in console! { object data1 = FETCH(true); object data2 = FETCH(false); //maybe to go through both objects: object[] allData …

Member Avatar for Mitja Bonca
0
3K
Member Avatar for rockout15

To get items that are selected (the same as all of them), you have to do a loop, and go through them one by one, and do insertion into database. Example: [CODE] SqlConnection conn = new SqlConnection("connString"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = @"INSERT INTO MyTable VALUES (@param1)"; cmd.Parameters.Add("@param1", …

Member Avatar for rockout15
0
95
Member Avatar for noobprogrammerr

I didnt actually get you completely. Would you like to rise an event when you choose some date? Please clarify it a bit better. thx

Member Avatar for noobprogrammerr
0
173
Member Avatar for compulove

Do it this way: [CODE] protected void Login_Authenticate(object sender, AuthenticateEventArgs e) { Boolean blnresult = Authentication("userName", "password"); //provide 2 arguments in here!!!! if (blnresult == true) { e.Authenticated = true; Session["Check"] = true; } else e.Authenticated = false; } protected static Boolean Authentication(string Username, string Password) { string sqlstring; sqlstring …

Member Avatar for compulove
0
175
Member Avatar for superjj

Abstract method cannot have any code implementation. Only overriden from it.

Member Avatar for Mitja Bonca
0
181
Member Avatar for david barman

About which password are you talking about? There can be plenty of them.

Member Avatar for Mitja Bonca
0
26
Member Avatar for techlawsam

Do it this way: [CODE] class Program { static void Main(string[] args) { Invoice someQuantity = new Invoice("1", "some description", 100, 120); Console.Write(someQuantity); Console.ReadKey(); } } class Invoice { public Invoice() { } public Invoice(string number) { this.InvNumber = number; } public Invoice(string number, string description) { this.InvNumber = number; …

Member Avatar for Mitja Bonca
0
179
Member Avatar for Jonathan C

Simply: [CODE] Random r = new Random(); private void button1_Click(object sender, EventArgs e) //generate numbers by click: { int total = r.Next(50, 1001); List<double> numbers = new List<double>(); for (int i = 0; i < total; i++) numbers.Add(Math.Round(0.0 + r.NextDouble() * 100.0, 2)); textBox4.Text = String.Join(", ", numbers.Select(s => s.ToString()).ToArray()); …

Member Avatar for Momerath
0
936
Member Avatar for Behseini

Yep, ShowDialog() will make the form to be TopMost all the time when opened. While Open it only puts the form on top of all when opened, and if you click some other form, this one will be hidden bellow newly clicked form.

Member Avatar for Behseini
0
260
Member Avatar for newbie26

I did an example code for you only, so you can see how this should be done: [CODE] Private dgv As DataGridView Private tableMain As DataTable Public Sub New() InitializeComponent() 'creating and adding columns to dgv: dgv = New DataGridView() dgv.Width = 470 Me.Controls.Add(dgv) 'get data from DB: tableMain = …

Member Avatar for newbie26
0
239
Member Avatar for moshe12007

Maybe the error occures this line: [CODE]imgCapture.Image = imgVideo.Image;[/CODE] if imgVideo is a pictureBox, there is no image inside of this control yet, thats why you get this error. Try putting this code into OnShow() overriden method. Just create (write) this event: [CODE] protected override void OnShown(EventArgs e) { base.OnShown(e); …

Member Avatar for Mitja Bonca
0
215
Member Avatar for ganil_22

I would suggerst you to get some book for beginners. It will really help you out, because you have to get some basics before going into coding. A good one for you would be [URL="http://www.amazon.com/Illustrated-2010-Experts-Voice-NET/dp/143023282X"]Illustrated C# 2010[/URL] (or 2008).

Member Avatar for Mitja Bonca
0
146
Member Avatar for VIPER5646

You have one main dataTable with all the data. When you want to filter it, create new DataTable, create same column as main one has (by using Clone method): [CODE] Dim temp As New DataTable() temp = mainTable.Clone() 'this was you get the table structure - same as main one …

Member Avatar for VIPER5646
0
18K
Member Avatar for Behseini

Do it like: [CODE] //Program.cs file: static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1());// open Form1 } } //form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); new Form2().Show(); //open …

Member Avatar for Behseini
0
247
Member Avatar for BleepyE

Use can implement [URL="http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol.usercontrol(v=VS.90).aspx"]UserControl[/URL]. You can create more of them and you can then "loop" through them to show completely different controls in the same spot of form.

Member Avatar for Mitja Bonca
0
100
Member Avatar for rockout15

Bind dgv to some dataTable (1st create dataTable, columns for it, and then bind it to datagridview). Then use SqlDataAdapter class to do insert or update command.

Member Avatar for Mitja Bonca
0
100
Member Avatar for compulove

The End.