1,469 Posted Topics
Re: Check out this code: [CODE] private void buttonWrite_Click(object sender, EventArgs e) { List<string> list = new List<string>(new string[] { "a,", "b", "c" }); //out put example CreateAndWriteIntoFile(list); } private void buttonRead_Click(object sender, EventArgs e) { List<string> list = ReadFromFile(); } private void CreateAndWriteIntoFile(List<string> list) { string path = @"C:\MyFolder\myFile.txt"; using … | |
Re: I did an example code which populates dgv from a dataSet, and then gets the selected row`s data, and passed them to form2`s textBoxes. In my example I only have 2 column in the dataSet (as in dgv of course) and 2 textBoxes to populate on form2. Take a look, … | |
Re: Try doing a loop through foreach control of the form: [CODE] private void Insert() { foreach (Control c in this.Controls) { if (c is TextBox && c != null) { string valueOfTextBox = c.Text; } } } [/CODE] | |
Re: This should do it: [CODE] public partial class Form1 : Form { private int wordIdFunc; public int propWordId { get { return wordIdFunc; } set { wordIdFunc = value; } } public Form1() { InitializeComponent(); } public string Word() { string[] words = new string[4]; words[0] = "The"; words[1] = … | |
Re: Check it out here: [url]http://www.dreamincode.net/forums/topic/58021-deploying-a-c%23-application-visual-studio-setup-project/#-application-visual-studio-setup-project/[/url] Mitja | |
Re: For having images in the listView (on in some other control), best way is to use an ImageList. You put images inside, and from there show images in listView. For example, how to get images form a disc, send then to imageList and then to listView: [CODE] //for better accurecy … | |
Re: Sure, you cannot show an array in a messageBox (its like putting a string array into stirng - cant do). You have to get all values from an array into a string, then show it in messageBox: [CODE] string[] myname = new string[2]; myname[0] = "Shahid"; myname[1] = "Hussain"; string … | |
Re: Foreach is a loop. So you cannot assign it to read for one string. You did like: [CODE] string a = "a"; foreach(string b in a){} //this is an error! [/CODE] You have to do it like: [CODE] string[] array = {"a", "b"}; foreach(string b in array) { //get each … | |
Re: [QUOTE=jugnu;1491997]The problem is when i edit a record and the SelectedIndex of TabControl is not TabPage 3 and when i save the record without moving to TabPage 3 i receive an error shows that Input String was not in Correct Format. But when i move to that TabPage i receive … | |
Re: Try using SelecredIndices collection: [CODE] public Form1() { InitializeComponent(); //my test population: char[] array = "abcdef".ToCharArray(); for (int i = 0; i < array.Length; i++) listBox1.Items.Add(array[i]); listBox1.SelectionMode = SelectionMode.MultiExtended; } private void button1_Click(object sender, EventArgs e) { while (listBox1.SelectedIndices.Count > 0) listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]); } [/CODE] | |
Re: How will dataSet show some value from it, if its empty. YOu have to retrieve the value from dataSet to textBox, after its being populated. So put the code from 4th line, bellow the line where you do the filling ("Fill()" method). If this is not it, tell more about … | |
Re: Tabular? Whats is this? Does the dataGridView control satisify your expectations? So, back to your issue. Get wanted values from database( use DataTable to fill it up), then open Form2 (new pop-up window) and pass dataTable parameter to it (it can be passed in the constructor of form2). Then bind … | |
Re: As darkagn said. Heres an example: [CODE] private void PopulatingTextBoxes() { int id = GetNewId(); textBox1.Text = id.ToString(); } private int GetNewId() { int id = 0; using (SqlConnection sqlConn = new SqlConnection("ConnectionString")) { string query = "SELECT (MAX)ID FROM STU"; SqlCommand cmd = new SqlCommand(query, sqlConn); using (SqlDataReader reader … | |
Re: Something lke that? [CODE] private void method() { const int value = 5; string tag = "_"; string item = ""; for (int i = 0; i < value; i++) item += tag; MessageBox.Show("You have chosen " + value.ToString() + " underscores.\nThe result is: \"" + item + "\""); } … | |
Re: I have changed the code a bit, with using virtual and override. And did some small changes also. Take a look: [CODE] class Program { static void Main(string[] args) { Student s = new Student("Dave", 1234); s.Birthday(); s.Print(); Console.ReadLine(); } } class Person { protected string name; protected int age; … | |
Re: Try this: [CODE] private void method() { Random r = new Random(); string[] colors = { "blue", "red", "purple", "pink" }; string color = colors[r.Next(colors.Length)]; } [/CODE] | |
Re: Momerath already showed you how to use properites. This how you have to do: [CODE] public partial class Form1 : Form { private int n; public int N { get { return n; } } public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; } public void Increment() { n = n … | |
Re: Yes? Would you mind telling us some more, just a bit more? | |
Re: Hi, go to form designer, click on form, so the form`s border will have the focus. Now go to Properties window. There you will see a property called Icon. Select it, and click on button on the right. The "OpenFileDialog" will open and simpy look for your icon, and click … | |
Re: You can hind Form1, and open form2. [CODE]//on button click: Form2 f2 = new Form2(); this.Hide(); f2.Show();[/CODE] If you will close or dispose Form1, the whole application will close, thats because in Program class you called "Application.Run(new Form1());" so this holds up everything. | |
Re: No where. You can simply use an usual method, instead of cnstructor. Something like: [CODE] //on class1: Class2 c2 = new Class2(); c2.DoOnBeginning(); //on Class2: class Class2 { pubic Class2() { //constructor of class2 (its empty - but in use now) } public void DoOnBeginning() { //do some code! } … | |
Re: Why dont you simple paste the code in here? And add some of descrition about the issue? Please... every one does that. Mitja | |
Re: Or you can try this: [CODE] int index = 1; Array list = Enum.GetValues(typeof(sourceType)); string value = list.GetValue(index).ToString(); [/CODE] Mitja | |
Re: [QUOTE=AngelicOne;1487956]There's an error saying that the combobox is already b, inded to a datasource, thus cannot add new items. [/QUOTE] Add items to a dataSource, not to comboBox. When you have some control bind to a data source, you have to work then with the data source (inserting, updating, removing), … | |
Re: What is it that you want to split the string? Do you want to get all words into an array? | |
Re: Hi, it seems your connection string is not the right one. Have you checked [URL="http://connectionstrings.com/oracle"]here[/URL] for it? And are you sure about your parameters enters into connection string? Are defenatelly the right one? | |
Re: Hi, would you mind describling your issue a bit better? I really dont understand what would you like to achive. But somehow I would say choosing Buttons for this task isnt the right option. Have you thought of what Momerath has proposed to you? If you think differently, please go … | |
Re: Look at this code, it removes the duplications: [CODE] public partial class Form1 : Form { DataSet ds; public Form1() { InitializeComponent(); CreatingDS(); } private void CreatingDS() { ds = new DataSet(); DataTable table = new DataTable("MyTable"); table.Columns.Add("id", typeof(int)); table.Columns.Add("name", typeof(string)); string[] names = { "A", "B", "C", "A", "B" … | |
Re: Is this other forms already opened? | |
Re: Do you want to use a MultiLine textBox? If so, here is your answer: [CODE] public Form1() { InitializeComponent(); textBox1.Multiline = true; textBox1.ScrollBars = ScrollBars.Vertical; Method(); } private void Method() { int[] array = { 1, 2, 3, 4, 5 }; foreach (int value in array) textBox1.AppendText(value.ToString() + Environment.NewLine); } … | |
Re: [QUOTE=Kath_Fish;1487225]hey...i want to ask about how to convert string array to integer array. hope someone can help me. thanks.[/QUOTE] As long as the strings are only numbers (no commas or dots indside the string), you can convert the string into integer as Momerath shows abouve. Mitja | |
Re: Hi, your code looks pretty strange, especially the using(xxx) row, but I dont know what those variables mean, so hard to tell... Lets make it a bit different: [CODE] private void DeletingDataBase() { using (SqlConnection sqlConn = new SqlConnection("ConnectionString")) { using (SqlCommand cmd = new SqlCommand()) { string sqlQuery = … | |
Re: You need to use delegate, look at this my example: [CODE] 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 Feb27Exercise1 { public partial class Form1 : Form { System.Threading.Thread thread; delegate void TextBoxDelegate(string message); public Form1() { InitializeComponent(); } private void … | |
Re: Row height: [CODE] foreach (DataGridViewRow row in dataGridView1.Rows) row.Height = 30; [/CODE] | |
Re: Hi, check here: [url]http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_24657018.html[/url] | |
Re: [CODE] private static void Test() { List<string> list = new List<string>() { "A", "B", "C" }; IList<IList<string>> perms = Permutations(list); foreach (IList<string> perm in perms) { foreach (string s in perm) { Console.Write(s); } Console.WriteLine(); } } private static IList<IList<T>> Permutations<T>(IList<T> list) { List<IList<T>> perms = new List<IList<T>>(); if (list.Count … | |
Re: I still dont get it what you want to do. Please explain in some words what is your intention. Why is an array there, what do you put into it? Is it filled in the runtime (in the code), or does it fill from textBox (or some other control)? Why … | |
Re: Size is a read only property. Use Width and Height directly, Size is just a helper property if you need them as a Size object. [CODE] Form1 f = new Form1(); f.Height = 400; [/CODE] | |
Re: :) Check this out man: [CODE] private void method() { string allText = "1, 2, 3, 4, 5\n2, 3, 4, 5"; allText = allText.Replace(",", ""); string[] lines = allText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>(); for (int i = 0; i < lines.Length; i++) … | |
Re: My this code: [CODE] while (reader.Read()) { if(reader.GetValue(0) != DBNull.Value) listAtt.Items.Add(reader.GetValue(0).ToString()); //or better coding to get value: //listAtt.Items.Add((string)reader[0]); } [/CODE] This should do it. Mitja | |
Re: Look at this code how it should be done: [CODE] public partial class Form1 : Form { List<string> list; BindingList<string> bindingList; public Form1() { InitializeComponent(); string[] array = new string[] { "A", "B", "C" }; list = new List<string>(array); bindingList = new BindingList<string>(list); listBox1.DataSource = bindingList; listBox1.SelectedIndex = -1; } … | |
Re: You have to get the x,y location point of the control above.Then add to the "y" the height of this control and + 20. In my example, your new Control is my label, and my listBox is your BerichtInput: [CODE] int x = listBox1.Location.X; int y = listBox1.Location.Y; y = … | |
Re: Hi, You can use StreamReader to read rows, and the code will look like this: [CODE] public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { List<string> list = GetDataFromFile(); richTextBox1.Clear(); foreach (string item in list) richTextBox1.AppendText(item + Environment.NewLine); } private … | |
Re: You can see into this example code how it has to be done: [CODE] public partial class Form1 : Form { public Form1() { InitializeComponent(); Text[] arrayOfText = new Text[3]; string[] array = new string[] { "A", "B", "C" }; //Adding int Text Array: for(int i=0;i<arrayOfText.Length;i++) { arrayOfText[i].someText = array[i]; … | |
Re: I have an example code with a bit different approach: [CODE] //form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); string[] array = new string[] { "A", "B", "C" }; this.comboBox1.Items.AddRange(array); this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); } private void comboBox1_SelectedIndexChanged(object obj, EventArgs e) { string item = comboBox1.GetItemText(comboBox1.SelectedItem); … | |
Re: Hi, and welcome to programming. About your question, you have to give us an idea of what would you like to do. Then we`ll help you out. Mitja | |
Re: I will only add to ddanbe` post: If you are not in some dgv`s event handler you get the row number like: [CODE] private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex1 = e.RowIndex; int rowIndex2 = GetRowIndex(); } private int GetRowIndex() { int rowIndex = this.dataGridView1.CurrentCell.RowIndex; return rowIndex; } … | |
Re: [CODE]if(reader.Value(0) == DbNull.Value) { //code! }[/CODE] | |
Re: I will show some other way of using Threads and using boolean variable to stop it! Using thread.Abort() method is not a graceful way of stoping the thread. Not that its not correct (it does what its meant for), but there is a better any more appropriate way, as said, … | |
Re: btw, why do you need a timer in the code? I did what I thought you want. Tell me if this is it. [CODE] int sRight; int sLeft; public MainForm() { InitializeComponent(); this.KeyDown += new KeyEventHandler(MainForm_KeyDown); } private void MainForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Right) { if … |
The End.