Mitja Bonca 557 Nearly a Posting Maven

How do you intend to pass the data from DGV to textBox? On a row (cell) click?
Some other way?
If so, do it like:

textBox1.Text = dgv[ColumnIndex, RowIndex].Value.ToString();

if you want to add data to textBox (multiline) use += insted of = only and add "\r\n" before code:

textBox1.Text += dgv[ColumnIndex, RowIndex].Value.ToString() + "\r\n"; //for adding new line for next insert
daniel955 commented: nice +1
Mitja Bonca 557 Nearly a Posting Maven

Hi,
No code, no question.
Sorry.

Mitja Bonca 557 Nearly a Posting Maven

Check out this way by using DialogResult (and passing data between forms or classes):

'PROGRAM class    
Class Program

    ''' <summary>
    ''' The main entry point for the application.
    ''' </summary>
    <STAThread()>  _
    Private Shared Sub Main()
        Application.EnableVisualStyles
        Application.SetCompatibleTextRenderingDefault(false)
        Dim loginData As String = ""
        Dim l As Login = New Login
        If (l.ShowDialog = DialogResult.OK) Then
            'code returns form login (if you want you can get some data from there and pass it further:
            loginData = l.MYPROPERTY
        End If
        Application.Run(New Form1(loginData))
    End Sub
End Class
' LOGIN:
Public Class Login
    Inherits Form

    Public Property MYPROPERTY As String
    End Property

    Public Sub New()
        MyBase.New
        InitializeComponent
    End Sub

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        'all ok..
        'and close login form (and pass data if you want)
        MYPROPERTY = "hi from login"
        Me.DialogResult = DialogResult.OK
    End Sub
End Class
'MAIN FORM:
Public Class Form1
    Inherits Form

    Public Sub New(ByVal loginData As String)
        MyBase.New
        InitializeComponent
        MessageBox.Show(loginData)
        'Do with the data what ever you want to...
    End Sub
End Class
Mitja Bonca 557 Nearly a Posting Maven

Hi, fill DataTable with images from database (or where ever), an then do a loop throuh the rows of dgv, and paste image into each row (to each dgv_image_cell):

  //create image column
  DataGridViewImageColumn ic= new DataGridViewImageColumn();
  ic.HeaderText = "Images";
  ic.Image = null;
  ic.Name = "imageColumn";
  ic.Width = 100;
  dataGridView1.Columns.Add(ic);

 //then fill DataTable 
 //NOTE: Images should be in bytes saved into database!!!

 DataTable table = new DataTable();
 using(SqlConnection sqlcon = new SqlConnection("connString"))
 {      
     string strquery = "SELECT MyImageColumn FROM MyTable";  
     using(SqlDataAdapter da = new SqlDataAdapter(strquery, sqlcon))
     {
        da.Fill(table);
     }
 }
  //1.
  //now lets loop through the rows of dgv and add images from dataTable!
  //NOTE: BE CAREFUL on the number of rows in DGV, and in DataTable!!!
  //If they are not the same, create some conditions!!

  for(int i = 0; i < dataGridView1.Rows.Count; i++)
  {
      DataGridViewImageCell cell = table.Rows[i][ColumnName"] as DataGridViewImageCell;
      dataGridView1["imageColumn", i].Value = cell;
  }

  //OR:
  //2.
  //Lets loop through the rows of DataTable!
  //Be aware of the same issue as above - number of rows in both collections! 
  for(int i = 0; i < table.Rows.Count; i++)
  {
      DataGridViewImageCell cell = table.Rows[i][ColumnName"] as DataGridViewImageCell;
      dataGridView1["imageColumn", i].Value = cell;
  }

Hope it helps,bye

Mitja Bonca 557 Nearly a Posting Maven

Momerath is right. I suggest you to do a little search over this forum (or uncle google) and Im sure will will soon fine a good solution.
And btw, you are learning, not we. So we would like to see some attiture from you guys, not that only what you want is a working code from us.
Sorry.

Mitja Bonca 557 Nearly a Posting Maven

You should use DataRowView class to retreive item and value from comboBox:

Dim view As DataRowView = comboBox1.SelectedItem
Dim value As Object = view("ColumnNameForValueMember")
Dim item As Object = view("ColumnNameForDisplayMember")
textBox1.Text = item.ToString()

Put this code into comboBox SelectedIndexChanged event.

Mitja Bonca 557 Nearly a Posting Maven

Better to use null as both arguments, then passing some Time parameters to button (2nd example from above is the one you need). But only in case when you will not need and parameters from EventArguments, or sender - but I doubt you will need).
Else you can create EventArguments manully.

Mitja Bonca 557 Nearly a Posting Maven

Indeed, you code does not return some value on each possible step of the method.
Change it to:

         public bool GetAdministrators(string userName, string password)
        {
            SqlConnection conn = new SqlConnection("Data Source=(local); database=ManagementNAV; Integrated Security=True");
            SqlCommand cmd = new SqlCommand("GetAdministrators", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            bool bFlag = false;
            while (reader.Read())
            {
                if (reader["userName"].ToString() == userName && reader["password"].ToString() == password)
                {
                    bFlag = true;
                    break;
                }
            }
            reader.Close();
            return bFlag;
        }
Mitja Bonca 557 Nearly a Posting Maven

Use DataReader class and Add items to comboBox:

Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:MyFolder\MyProject\myAccessDatabase.accdb"
Dim conn As New OleDbConnection(connString)
Dim sql As String = "SELECT ColumnName FROM Clientes"
Dim cmd As New OleDbCommand(sql, conn)
conn.Open()
Dim reader As OleDbDataReader = cmd.ExecuteReader()
While reader.Read()
    comboBox1.Items.Add(reader(0).ToString())
End While
reader.Close()
conn.Close()
cmd.Close()
Mitja Bonca 557 Nearly a Posting Maven

I would like you to continue using Linq, which is really some piece of work from MS.

To get 1st 50 words:

string text = "you long string";
var result_1st50 = text.Split(' ').Select(s=>s.Lenght).Take(50).ToList();

To get next 50 (and skip 1st 50):

var result_1st50 = text.Split(' ').Select(s=>s.Lenght).Skip(50).Take(50).ToList();

As you can see, Skip will skip the number of words, while Take will get the number of words. For example if you wanna get words from 350 to 400, you only change:
//.Skip(350).Take(50).ToList();

ToList() is the annonimus method, that already create a new list of strings, so no need of any further loop.

Mitja Bonca 557 Nearly a Posting Maven

The simpliest way would be to spit the string by white spaces into string array, and count the words (by Length property):

string text = "you long string";
string[] splitted = text.Split(' ');
int wordsCount = splitted.Length;

Or even better (shorter), by using Linq:

int a = text.Split(' ').Select(s => s.Length).Count();
coder389 commented: Now, how will I display the first 50 words, then next 50 words and so on? +0
Mitja Bonca 557 Nearly a Posting Maven

You have to get an image from database to byte array, and with StreamReader then pass it to pictureBox:

Dim ImageByte As Byte() = Nothing
Dim MemStream As MemoryStream = Nothing
Dim PicBx As New PictureBox()
Dim OB As Object
Dim WorkingDirectory As String = Application.StartupPath + "\"
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & WorkingDirectory & "DBFile.mdb; Persist Security Info=True"
cnction = New OleDbConnection(connString)
cnction.Open()
Dim ImageID As Integer = 6
sqlCommand = "SELECT ImageObject FROM ImagesTable WHERE ImageID = " & ImageID & ""
comm = New OleDbCommand(sqlCommand, cnction)
ImageByte = comm.ExecuteScalar()
MemStream = New MemoryStream(ImageByte)
PictureBox1.Image = Image.FromStream(MemStream)
Mitja Bonca 557 Nearly a Posting Maven

Using some Regex will do:

Dim text As String = "<td class=""bld""><span id=""ref_12590587_l"">5,304.48</span>"
Dim regularExpressionPattern As String = "\>(.*?)\<"
Dim re As New Regex(regularExpressionPattern)
Dim dec As Decimal
Dim str As String = ""
For Each m As Match In re.Matches(text)
    str = m.Value.Replace(">", "").Replace("<", "")
    If str.Length > 0 Then
        If str.Contains(",") Then
            str = str.Replace(",", "")
        End If
    End If
Next
Begginnerdev commented: Good job, Mitja. +5
Mitja Bonca 557 Nearly a Posting Maven

In this case, we have to re-do your code completely. Usin some Linq and an additional method. I did think of something like this:

        private void YourMethod()
        {
            double media = 1.8815;
            List<double> lista = new List<double>();
            lista.Add(2.201);
            //and other values...

            List<double> aux = new List<double>();
            for (int i = 0; i < lista.Count; i++)
            {
               if(CheckNext5(media, lista.Skip(i).Take(5).ToList()))
               {
                   for (int j = 0; j < 5; j++)
                       aux.Add(lista[i + j]); 
                   i = i + 4;
               }
            }
        }

        private bool CheckNext5(double media, List<double> list)
        {
            bool bFlag = true;
            foreach (double item in list)
            {
                if (item < media) 
                {
                    bFlag = false;
                    break;
                }
            }
            return bFlag;
        }

There is a method, that checked next 5 values if they are higher then the media variable, is so, they are added to the new list, else, loops goes on to get next values.
ps: vote and add a comment :)

Hope you like it :)

Mitja Bonca 557 Nearly a Posting Maven

You means to add all numbers (of 5 in a row) if higher then the media into new list?

Mitja Bonca 557 Nearly a Posting Maven

If so, you can do it like:

List<double> aux = new List<double>();
int counter = 0;
for (int i = 0; i < lista.Count; i++) 
{
    if(counter == 5)
        break;
    if(lista[i] > media && counter <= 5)
    {
        aux.Add(list[i]);
        counter++;
    }   
    else
    {
        counter = 0;
        aux.Clear();
    }
}

//show values...
chromatinpt commented: 1 +1
Mitja Bonca 557 Nearly a Posting Maven

It clears because cooner or later your code goes to else block, and clears the list.

But I actually dont get it which value would you like to put into aux list from lista. Can you clarify it a bit better?

Do you mean that tin the for loop you check the current value, and if this and next 5 values are higher then the media value, you put all these 5 values into aux list?
And you continue loopint to the end of the items in lista?

Mitja Bonca 557 Nearly a Posting Maven

1st of all, if you use radionButton, there is always one selected (its not the same as checkBoxes, where you can deselect all). Ok, its possible to deselect all radionButtons in a group as well, but this is not the purpose then in using radionButtons.

About showing the button control, when there is some text inside a textBox, you can use a Length property to check how long is the actual text, and show/hide button based on that - inisde the TextChanged event (just subscribe to in, on double clicking on it in winform designer:

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if(textBox1.Text.Length == 0) //checking if there is any text inside textBox - if there is at least 1 character, buttoon will show up
    {
        button1.Visible = false;
    }
    else
    {
        button1.Visible = true;
    }
}
Mitja Bonca 557 Nearly a Posting Maven

Iam glad you found it. I told you there has to be some code that does changes.
From now on you will know where to look if this kind of issue appears.
bye

Begginnerdev commented: Good job Mitja! +5
Mitja Bonca 557 Nearly a Posting Maven

or;

'1
Dim controls As TextBox() = Me.Controls.OfType(Of TextBox)().OrderBy(Function(o) o.Name).ToArray()
'then you can loop in foreach (like bellow)

'2.
For Each control As var In Me.Controls.OfType(Of TextBox)()
    Dim name As String = control.Name
Next
Begginnerdev commented: Good alternative! +5
Mitja Bonca 557 Nearly a Posting Maven

Whole code would be:

string connectionString = "Data source=localhost;Database=locations;user id=root;password=ietmdb;";
DataTable tables = new DataTable("Tables");
using (SqlConnection connection = new SqlConnection(connectionString))
{
    using(SqlCommand command = connection.CreateCommand())
    {
        command.CommandText = "select table_name as Name from INFORMATION_SCHEMA.Tables where TABLE_TYPE = 'BASE TABLE'";
        connection.Open();
        tables.Load(command.ExecuteReader(CommandBehavior.CloseConnection));
    }    
}

foreach(DataRow row in table.Rows)
{
    DropDownList1.Items.Add(row[0].ToString());
}
Mitja Bonca 557 Nearly a Posting Maven

try using this select query statement:

"select table_name as Name from INFORMATION_SCHEMA.Tables where TABLE_TYPE = 'BASE TABLE'";
Mitja Bonca 557 Nearly a Posting Maven

Variable (in your case a generic list) declared as public static is one solution to use it all over the project.
But if has its own weaknesses, like that it stays in memory for as long as your project is alive. And if the variable becomes huge, it can eat a lot of memory.
If you want to free the memory you should set the field to null so that the object the field has been pointing to becomes eligible for GC.
This only points out something: try to avoid static variables.

-------
What I would do to hold same referecne through all the classes of a project, is to pass the class reference to all the other classes, this way, you can access to non-static public field (or property).
Example:

class ClassForVarialbe
{
     public List<string> stageManagementList;

     public ClassForVariable()
     {
         stageManagementList = new List<string>();
     }

     //...
     //you can even create a common method to do or check something     

}


class Class1
{

     void StartingMethod()
     {
          //here we`ll instantiate a new variable (generic list):
          ClassForVariable cfv = new ClassForVariable();
          //to access to the public variable and ADD into it, you can use the class referecne:
          cfv.stageManagementList.Add("one");

          //now open other class (and pass the referecne or a class where out variable is);
          Class2 c2 = new Class2(cfv); //pass a class referecne
          c2.AddToList(); //examle from class2 how to add into same list

          //now open class3 and print data from list out:
          Class3 c3 = new Class3(); 
          c3.ReadFromList(cfv); //pass …
Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

Sure it doesnt.
Why you called listView1.Clear() method? This clears all the data and columns.
Do only:

listView1.Items.Clear()
Mitja Bonca 557 Nearly a Posting Maven

ok, I did this code in 5 minutes, so error are possible.
You can vote +1 and add some comment :)

thines01 commented: Persistence +12
Mitja Bonca 557 Nearly a Posting Maven

Try it this way:

' 1. create columns ot listView!!
' 2. then loop through the row and columns to datatable:
' NOTE: make sure that the number of columns in listView IS equal to columns to datatable!!

For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
    Dim lvi As New ListViewItem()
    For j As Integer = 0 To ds.Tables(0).Rows(i).ItemArray.Length - 1
        lvi.SubItems.Add(ds.Tables(0).Rows(i)(j).ToString())
    Next
    listView1.Items.Add(lvi)
Next
ponkan20 commented: thank you~ =) +0
Mitja Bonca 557 Nearly a Posting Maven

There is really a problem in your do-while loop. You can NOT have it in windows forms.
Why?
Simply, when you clicked the button, you cannot edit your variable any longer, so the while loop will be infinitive.
While loop can be in console, but now here, in this kind of form like you have it.

This is how you should do in win form:

        Random RandomNumber = new Random();
        bool bGuessed;
        int guessedNumber;
        int secretNumber;
        int counter;
        private void button2_Click(object sender, EventArgs e)
        {
            //1st click the button to set new number, then start guessing!
            if (!bGuessed)
            {
                //set to new number (but only after pevious one was guessed!
                secretNumber = RandomNumber.Next(1, 11);
                MessageBox.Show("New round is starting. Guess new number from 1 to 10.");
                bGuessed = true;                
            }
            else
            {
                if (int.TryParse(textBox1.Text.Trim(), out guessedNumber))
                {
                    if (guessedNumber == secretNumber)
                    {
                        MessageBox.Show("Correct guess!\r\nYou needed " + counter + " clicks.");
                        counter = 0;
                        bGuessed = false;                        
                    }
                    else if (guessedNumber < secretNumber)
                    {
                        MessageBox.Show("Higher than that!");
                        counter++;
                    }
                    else if (guessedNumber > secretNumber)
                    {
                        MessageBox.Show("Lower than that!");                        
                        counter++;
                    }
                }
                else
                    MessageBox.Show("This is not a number.");
            }
            Clering_Focusing();
        }

        private void Clering_Focusing()
        {
            textBox1.Clear();
            textBox1.Focus();
        }

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven
prerit commented: Thank you for your help.Your link solved my prob +0
Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to split into array rather then adding a whitespace (you can still add a whitespace when you have an array);

    static void Main(string[] args)
    {
        string iPAddress = "11111111111100000000000001111111";
        string[] ipSeperated = SplitString(iPAddress, 8);
    }

    static string[] SplitString(string str, int size)
    {
        return Enumerable.Range(0, str.Length / size)
                         .Select(i => str.Substring(i * size, size)).ToArray();
    }

If you wanna add a white space you can do by using String.Join method.

    string newId = string.Join(" ", ipSeperated);

This is it.
Hope you like it.
bye

Mitja Bonca 557 Nearly a Posting Maven

Just remove or comment this line: comboBox1.Text = "" from comboBox2_SelectedIndexChanged events.
Change to:

   Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
    comboBox2.Text = ""
    comboBox2.Items.Clear()
    For Each time As DateTime In times
        comboBox2.Items.Add(time.ToString("t"))
    Next
End Sub

Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
    'comboBox1.Text = "";  remove or comment this line

    comboBox1.Items.Clear()
    comboBox1.Items.Add(time.ToString("t"))
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Finally we agree.
Here is the solution that works - as we came to the concludion:

Public Partial Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
        comboBox1.Items.Add("6:00 am")
    End Sub

    Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
        comboBox2.Text = ""
        comboBox2.Items.Clear()
        For Each time As DateTime In times
            comboBox2.Items.Add(time.ToString("t"))
        Next
    End Sub

    Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
        comboBox1.Text = ""
        comboBox1.Items.Clear()
        comboBox1.Items.Add(time.ToString("t"))
    End Sub

    Private Function Data_Combo1(input As String) As DateTime
        Dim time As DateTime = DateTime.Parse(input, System.Globalization.CultureInfo.InvariantCulture)
        Return time
    End Function

    Private Function Data_Combo2(input As String) As List(Of DateTime)
        Dim time As DateTime = DateTime.Parse(input, System.Globalization.CultureInfo.InvariantCulture)
        Dim list As New List(Of DateTime)()
        Select Case time.Minute
            Case 0
                If True Then
                    list.Add(time.AddMinutes(30))
                    list.Add(time.AddMinutes(45))
                    list.Add(time.AddMinutes(50))
                    list.Add(time.AddMinutes(60))
                    Exit Select
                End If
            Case 30
                If True Then
                    list.Add(time.AddMinutes(15))
                    list.Add(time.AddMinutes(20))
                    list.Add(time.AddMinutes(30))
                    Exit Select
                End If
            Case 45
                If True Then
                    list.Add(time.AddMinutes(5))
                    list.Add(time.AddMinutes(15))
                    Exit Select
                End If
            Case 50
                If True Then
                    list.Add(time.AddMinutes(10))
                    Exit Select
                End If
        End Select
        Return list
    End Function

End Class

Let me know how its gonna work.

Mitja Bonca 557 Nearly a Posting Maven

You can try it this way:

            List<string> values = new List<string>();
            using (SqlConnection conn = new SqlConnection())
            {
                using (SqlCommand cmd = new SqlCommand(@"SELECT Col1, Col2, Col3, Col4 FROM MyTable", conn)) //change your table name
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            values.Add(reader[0].ToString());
                            values.Add(reader[1].ToString());
                            values.Add(reader[2].ToString());
                            values.Add(reader[3].ToString());
                        }
                    }
                }
            }
            List<string> distinctValues = values.Select(s => s).Distinct().ToList();
ravi.26jani commented: list error coming +0
Mitja Bonca 557 Nearly a Posting Maven

Try:

this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
Mitja Bonca 557 Nearly a Posting Maven

This for sure is a a school project (isnt it)?
So, do you have created any code? Show us how it really looks this Array.

Anyway, indexes must have numbers (not must, there always is a number, because array[T] means array as number T has some value), othwewise this is not an array. This really is some strange homework.

Mitja Bonca 557 Nearly a Posting Maven

**Are you sure you have the right connection string? **
And if there are data inside details table?
If so you can try this code:

MySqlConnection myconn = new MySqlConnection("server=localhost;user id=root;password=db;database=workers;");
string strSQL = @"SELECT * FROM details";
MySqlDataAdapter mydata = new MySqlDataAdapter(strSQL, myconn);
DataTable table = new DataTable("myTable");
mydata.Fill(table);
GridView1.DataSource = table.DefaultView;
//close and  dispose all iDisposable objects on the end!

This has to work 100% if all is ok (connection string and if there are data inside table). There is really nothing else that can be wrong for not showing data in dgv.

Mitja Bonca 557 Nearly a Posting Maven

Thx for reminding me (it really was a type). Here is repaired code:

var query = descQuantity.Where(w=>w.Price >= 250M && w.Price <= 550M).Select(s => new Invoice { Id = s.Id, Name = s.Name, Quantity = s.Quantity }).ToList();
Mitja Bonca 557 Nearly a Posting Maven

Sure, change if loops with while.

Mitja Bonca 557 Nearly a Posting Maven

Try creating DataTable and fill it with data, if there wil be no rows inside of it, return false, if there are rows, return true:

Private Function CheckingData() As Boolean
    Dim con As New System.Data.SqlClient.SqlConnection("Data      Source=CHETS-TOSHIBA\SQLEXPRESS;Initial Catalog=PlanetDiscLibrary;Integrated Security=True")
    Dim sqls As String = "Select * from album where album_id='" + txtAID.Text & "' and quantity_available < 1 "
    Dim cmd As New System.Data.SqlClient.SqlCommand(sqls, con)
    Dim table As New DataTable()
    Dim ds As New System.Data.SqlClient.SqlDataAdapter()
    da.Fill(table)
    If table.Rows.Count > 0 Then
        Return True
    Else
        Return False
    End If
End Function

Not to forget: to show messageBox, but show it in the other method, not here:

Private Sub MyMethod()
    Dim bChecking As Boolean = CheckingData()
    'call method which will check for data existance
    If bChecking Then
        MessageBox.Show("Data exists")
    Else
        MessageBox.Show("Album is out of stock")
    End If
End Sub
Begginnerdev commented: Same method that I use. Good job. +0
Mitja Bonca 557 Nearly a Posting Maven

Sorry, but we are here to help, nothing else.
If you wont show any effort, we cannot show it too.

And if you are a bit of a programmer, you can easily do something, it seems a easy task (if at least you know something about coding).
So, whats it gonna be?

Mitja Bonca 557 Nearly a Posting Maven

Ok, I mess around a bit with the code you want to, and this is what came out.
I hope you like it:

public partial class Form1 : Form
{
    DataTable table;
    public Form1()
    {
        InitializeComponent();
        //I will create this code in form`s constructor, so you will see it when form shows up

        //creating and setting dgv:
        DataGridView dataGridView1 = new DataGridView();
        dataGridView1.Location = new Point(20, 20);
        this.Controls.Add(dataGridView1);
        dataGridView1.AutoSize = true;
        dataGridView1.AllowUserToAddRows = false;
        dataGridView1.RowHeadersVisible = false;

        //creating datatable:
        table = new DataTable();
        for (int i = 1; i < 7; i++)
        {
            table.Columns.Add(string.Format("c{0}", i), typeof(int));
            table.Rows.Add();
        }

        //main code for sorting numbers in your way:
        int[] nums = Enumerable.Range(1, 36).ToArray();
        int x = 2, y = 3;
        int[] steps = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5 };
        int number = 1;
        int side = 1;
        //sides: 1 = right, 2 = up, 3 = left, 4 = down

        //lets insert 1st starting number:
        InsertNumber(x, y, nums[0]);
        for (int i = 0; i < steps.Length; i++)
        {
            SettingSteps(steps[i], ref side, ref number, ref x, ref y);
            if (side == 4)
                side = 1;
            else
                ++side;
        }
        //setting datasource to datagridview to show result:           
        dataGridView1.DataSource = table.DefaultView;
        for (int i = 0; i < dataGridView1.Columns.Count; i++)
            dataGridView1.Columns[i].Width = 30;
    }

    private void SettingSteps(int steps, ref int side, ref int num, ref int x, ref int y)
    {
        for (int i = 0; i < steps; i++)
        {
            switch (side)
            {
                case 1: x++; break; …
Mitja Bonca 557 Nearly a Posting Maven

Still hard to tell, since he didnt tell us what exactly he expects from the query.

Mitja Bonca 557 Nearly a Posting Maven

variable "a" seems to be null, or has no value at all.

Begginnerdev commented: Good catch. +0
Mitja Bonca 557 Nearly a Posting Maven

Why you dont want to show all the records from the text file in datagridview at ones?
Like:

string[] rows = File.ReadAllLines(@"C:\1\test35.txt");
            DataTable table = new DataTable("customers");
            table.Columns.AddRange(new DataColumn[] 
            { 
                new DataColumn("First name", typeof(string)), 
                new DataColumn("Middle name", typeof(string)), 
                new DataColumn("Last name", typeof(string)), 
                new DataColumn("Born", typeof(DateTime)), 
                new DataColumn("Gender", typeof(string)) 
            });
            DataRow dr;
            for (int i = 0; i < rows.Length; i++)
            {
                string[] columns = rows[i].Split(',');
                dr = table.NewRow();
                if (columns.Length == 5) //with middle name
                {
                    dr["First name"] = columns[0];
                    dr["Middle name"] = columns[1];
                    dr["Last name"] = columns[2];
                    dr["Born"] = columns[3];
                    dr["Gender"] = columns[4];
                }
                else if (columns.Length == 4) //no middle name (if it might occur)!
                {
                    dr["First name"] = columns[0];
                    dr["Last name"] = columns[1];
                    dr["Born"] = columns[2];
                    dr["Gender"] = columns[3];
                }
                table.Rows.Add(dr);
            }
            //bind table to datagridview:
            dataGridView1.DataSource = table.DefaultView;
ddanbe commented: Nice. +15
Mitja Bonca 557 Nearly a Posting Maven

Try do use StreamReader class to read the file line by line, and count repetitions of char:

Dim counter As Integer = 0
Using sr As New StreamReader("filePath")
	Dim line As String
	Dim data As String() = Nothing
	While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
		If line.Contains("*"C) Then
			data = line.Split(New Char() {"*"C}, StringSplitOptions.None)
			counter += data.Length - 1
		End If
	End While
End Using
MessageBox.Show("char * was counted: " & counter & " times")
Mitja Bonca 557 Nearly a Posting Maven

or do a loop through all the textboxes and clear them (or what ever you want to do with them):

For Each t As TextBox In Me.Controls.OfType(Of TextBox)()
	t.Text = String.Empty
Next
Reverend Jim commented: "OfType(Of TextBox)" cool. I didn't know that one. +9
M.Waqas Aslam commented: i also dont know this quick method .:P thanks +5
Mitja Bonca 557 Nearly a Posting Maven

Maybe something like this:

static int Find(int el, int[] a)
        {
            int index = -1;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == el)
                {
                    return a[i];
                }
            }
            return index;
        }
Mitja Bonca 557 Nearly a Posting Maven

This is all the code you need:

//on form1:
        int counter;
        Form2 f2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (counter < 5)
            {
                f2 = new Form2();
                counter++;
                f2.Show();
            }
            else
                MessageBox.Show("Form2 cannot be opened any longer.");
        }
Mitja Bonca 557 Nearly a Posting Maven

This is a simple code, that creates an array of 4 integers, and addes a random number to each index.

Dim r As New Random()
Dim nums As Integer() = New Integer(3) {0, 0, 0, 0}
For i As Integer = 0 To 3
	If nums.Sum() <= 100 Then
		nums(i) = r.[Next](1, 101)
	Else
		nums(i - 1) = 0
		nums(i - 1) = 100 - nums.Sum()
		Exit For
	End If
Next
If nums.Sum() < 100 Then
	nums(3) = 100 - (nums(0) + nums(1) + nums(2))
End If
timosoft commented: Execellent +1
Mitja Bonca 557 Nearly a Posting Maven

Who voted -1 for me and why?
damn thx, really appreciate it.

About your error: Check the TYPE of your column before we continue. Is it a bit type, is it a varchar, or what?
No need to vote -1, if the error is yours!!!