1,469 Posted Topics
Re: 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] | |
Re: Hi, check [URL="http://stackoverflow.com/questions/232395/how-do-i-sort-a-two-dimensional-array-in-c"]here[/URL] for solution. | |
Re: 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] | |
Re: 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] | |
Re: 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. … | |
Re: 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 … | |
Re: 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] | |
Re: 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) … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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[] … | |
Re: 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] | |
Re: 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 … | |
Re: simpliest way: [CODE] Dim data As String() = comboBox1.SelectedItem.ToString() textBox1.Text = data(0) textBox2.Text = data(1) [/CODE] | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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 = … | |
Re: So you want to display one one item? If one, which one? If more, you better use Listobx control. | |
Re: 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 … | |
Re: 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 = … | |
Re: 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 … | |
Re: 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] | |
Re: 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). | |
Re: 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 … | |
Re: 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); } … | |
Re: Where exactly do you get this error? On which line of code? | |
Re: 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] | |
Re: 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 … | |
Re: To do the focus and highligh all the text inside ot it: [CODE] texrBox1.Focus() texrBox1.SelectionStart = 0 texrBox1.SelectionLength = textBox1.Text.Lenght [/CODE] | |
Re: 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) { } … | |
Re: try with: [CODE]listBox1.Font = New Font("Arial", 10, FontStyle.Regular)[/CODE] | |
Re: 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 … | |
Re: 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", … | |
Re: 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 | |
Re: 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 … | |
Re: Abstract method cannot have any code implementation. Only overriden from it. | |
Re: About which password are you talking about? There can be plenty of them. | |
Re: 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; … | |
Re: 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()); … | |
Re: 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. | |
Re: 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 = … | |
Re: 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); … | |
Re: 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). | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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. | |
Re: What are you doing, some kind of a login? |
The End.