Mitja Bonca 557 Nearly a Posting Maven

LOL ...
My code works 100%, and it instets 1 row from dataTable to the last row of datagridview!!!
How you changed it? Do you know whta to change?
What is this code:

int rowIndex = dataGridView1.Rows.Add();

This code throws an error!!

Please paste my code into your code, all you have to do to use your own variable names.

Mitja Bonca 557 Nearly a Posting Maven
datagridview1.Rows.Add(); //add new row to dgv control
int rowIndex = datagridview1.Rows.Count - 1; //get this row`s index

//now insert one row from dataTable:
//I will show you how to add 1st row from dataTable:
int rowIndex = dataGridView1.Rows.Count - 1;
for (int i = 0; i < table.Rows.Count; i++) //loop through thr rows of dataTable
{
    if (i == 0) //only add row at index 0 (1st row in dataTable)
    {
        for (int j = 0; j < table.Columns.Count; j++) //loop through thr columns of dataTable
        {
             dataGridView1[j, rowIndex].Value = table.Rows[i][j];
        }
        break; //when done, code will leave for loop (of rows) - makes code faster!
    }
}

Hope this helps.

Mitja Bonca 557 Nearly a Posting Maven

If you need data in run-time, then sure best option is to keep the data inisde classes, this is like you said using properties. If you want to store data for a longer run (when you close and re-open application), then its best to use xml or some files (ini, txt), or even thining of using dataBase.

Since you didnt specficly explained your needs, I cannot advice you better, so far.

Mitja Bonca 557 Nearly a Posting Maven

Can you show us some of your code? What type are those array lists? Of custom objects (classes) or some general type, lile string or integer?

Anyway, put then into one collection, and then do a loop through this collection. And try to find what you are looking for.

To create a collection you can use a generic list <T>, where T is array list:
List<ArrayList> arraysCollection = new List<ArrayList>();
list.Add(arrList1);
list.Add(arrList2);
//and so on, you can use AddRange method instead of Add too.

Then do the looping:
string keyWord = "something";
foreach(ArrayList list in arraysCollection)
{
    foreach(YourArrayType item in list) //YourArrayType is custom class, string ot int,...
    {
         if(keyWord == item)
         {
               //item found!!
         }
    }
}

This is only an example how to do the search, since I have no more info, I can do no more (so far).

Mitja Bonca 557 Nearly a Posting Maven

Hi, check here for the answer.

Mitja Bonca 557 Nearly a Posting Maven

It doesnt matter much if you use Access database.
Then before binding data with the DGV, set datasoruce to null, like:

'set data source property:
datagridview1.DataSource =  Nothing 'reset binding
datagridview1.DataSource = New BindingSource(table, Nothing)'add new data source

Now there shouldnt be adding columns. Always should be there only 2 of them.

Mitja Bonca 557 Nearly a Posting Maven

Best and simpliest approach is to fill the DataTable from the dataBase data, and use dataSource property of dataGridView to bind data to it.

Like:

Dim table As New DataTable()
Using sqlConn As New SqlConnection("connString")
	Using da As New SqlDataAdapter("SELECT Column1, Column2 FROM MyTable", sqlConn)
		'you can add a WHERE clause in the query!
		da.Fill(table)
	End Using
End Using
'set data source property:
datagridview1.DataSource = New BindingSource(table, Nothing)
Mitja Bonca 557 Nearly a Posting Maven

You have to pass the DataTable from form where button1 is located (form1 or whatever) to EditData class:

DataTable table;

private void FillDataTable()
{
      table = new DataTable();
      //fill it here...
}
private void button1_Click(object sender, EventArgs e)
{     
    EditData ed = new EditData(); 
    ed.TryIt(table); //pass data as argument
    this.Close(); //I dont know why you close, but ok...
}
//class EditData
class EditData  //is this a Form class (because if its not, you cannot use ListView control 
                //just asking...
{
     public EditData()
     {
          //create columns for listView:
          listView1.Columns.Add("id", 50, HorizontalAlignment.Left);
          listView1.Columns.Add("Name", 80, HorizontalAlignment.Left);
          //and so on...
     }
 
     public void TryIt()
     {
           int c = 1;
           listView.Clear();
           foreach (DataRow row in ds.Tables[0].Rows) // update listview1
           {
                ListViewItem item1 = new ListViewItem(c.ToString());                   
                item1.SubItems.Add(row["Name"].ToString());
                item1.SubItems.Add(row["LastName"].ToString());
                item1.SubItems.Add(row["Password"].ToString());
                item1.SubItems.Add(row["Notes"].ToString());
                listView1.Items.Add(item1);
                c++;
           }
     }
}
Mitja Bonca 557 Nearly a Posting Maven

What exactly is not working?
Does it work anything at all?

If you dont know exactly, set a break point just before this code, and go through it line by line, using F11 key.
This way you will exactly see whats really going on while looping through those two loops.

I double checked code i gave you, and it should work fine - if you are trying to find one person at a time.
PS: check if columns at index 3 are ok, if there isn`t any other index.

Mitja Bonca 557 Nearly a Posting Maven

Since your data is seperated by a delimiter (comma), you can do an array of data.
Then each index of an array will be holding each seperated data like address1, address2, city,..
This way will be faster and easier to sepetate.

So you can do:

string[] dataArray = myOutput.Split(',');
//so you now have all data in the array splitted:
string addr1 = dataArray[0];
string arr2 = dataArray[1];
string city = dataArray[2];
//and so on...
Mitja Bonca 557 Nearly a Posting Maven

Impossible.

Mitja Bonca 557 Nearly a Posting Maven

Why? We don't delete threads without good reason, especially when there are replies.

Yep, you intentioanlly created this thread, with some "interesting" topic.
If you found your answer, please mark the thread as answered (you can even add some rep. point to individuals), so this thread will be closed.

PS: If your boss doesn`t let you using try, catch blocks, tell him he doesn`t have a clue about programming. And so you can close this thread as well.

Mitja Bonca 557 Nearly a Posting Maven

:)
you too.
I know how it feels like when you want to do something very badly, and you cannot succeed it. Thats why I wanna give others as much as I know.
bye

Mitja Bonca 557 Nearly a Posting Maven

Hm, you didnt say last time when I did this code for you, you will be using a new member insertion.
If so, you have to do it a bit differently, you have to check if a user from the dataTable exists in DGV, and if not, then you can insert a new member.

Like:

bool bUserExistance = false;
            //foreach datagridRow in datagrid
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                // if not a new row
                if (!row.IsNewRow) //checking for a new row
                {
                    if (!bUserExistance)
                    {
                        string memberDGV = dataGridView1[3, row.Index].Value.ToString();
                        // foreach dataRow in dataTable
                        foreach (DataRow dr in table.Rows)
                        {
                            string memberDT = dr[3].ToString();
                            if (memberDGV == memberDT)
                            {
                                bUserExistance = true;
                                break;
                            }
                        }
                    }
                    else
                        break;
                }
            }

            if (!bUserExistance)
            {
                // MessageBox.Show("member is not in here");
                insertMember();
                insertDate();
            }
            else
            {
                // MessageBox.Show("Member is in dgc");
                insertDate();
            }

SO this code now will go through all the rows of DGV and on each row will check all the rows of DataTable. If the use will be found, it will leave the both loops. If user will not be found will (for sure loop both the loops to the end), and when (in both cases) when leave the Rows of DGV loop, it will execute the code, regarding on the boolean flag.

Hope this will salve your problem.

Mitja Bonca 557 Nearly a Posting Maven

btw, the code above creates only 6 label. You will create 180 (or what ever). These labels are created all in a run time, so nothing in needed just a clear form2 (nothing on it).
Be careful on Location property of each label, I position labels no one under another - you can do it differently (depends on your needs).

bye

Mitja Bonca 557 Nearly a Posting Maven

Ok, I did a code, which uses its own class, and a property. Property is a generic list, type of Label. So into this property are saving clicked labels (using SET access modifier), and when you want to show already clicked lables, the code uses GET access modifer to set appropriate labels (their forecolor proiperty).

I was thinking that this Labels are on Form2 (which is opened from Form1), so when re-opening a form2, it will automatically set label which have been clicked before.
If none clicked, of form2 is opened for the 1st time, will happen nothing.

So, heres the code:

Public Partial Class Form2
	Inherits Form
	Private labels As Label()
	Public Sub New()
		InitializeComponent()

		labels = New Label(5) {}
		Dim x As Integer = 20, y As Integer = 20
		For i As Integer = 0 To labels.Length - 1
			labels(i) = New Label()
			labels(i).Name = "label" & i
			labels(i).Location = New Point(x, y)
			labels(i).Text = GetQuestions(i)
			'this is my own way of creating questions...
			labels(i).Click += New EventHandler(AddressOf Labels_Click)
			labels(i).Tag = i
			labels(i).ForeColor = Color.Black
			Me.Controls.Add(labels(i))
			y += 25
		Next
		If Questions.myLabels Is Nothing Then
			Questions.myLabels = New List(Of Label)()
		End If

		'setting forecolor to already clicked questions:
		For Each l As Label In Questions.myLabels
			Dim _tag As Integer = CInt(l.Tag)
			labels(_tag).ForeColor = Color.Red
		Next
	End Sub

	Private Function GetQuestions(i As Integer) As String
		Dim question As String = ""
		Select Case i
			Case 0
				question = "Question 1"
				Exit Select
			Case 1 …
Mitja Bonca 557 Nearly a Posting Maven

It really doesnt matter how many labels there are.
Are these question being answred one after another (in an order), or can be answered with no order?

Mitja Bonca 557 Nearly a Posting Maven

Timer.Elapsed method will be rised when The time set in the Interval peopery will go by. So is there any special code in the Elapsed method to catch?
Because from this upper code you pased, I cant se eany reason why to catch exception (or any error), becuase there isn`t any.

Mitja Bonca 557 Nearly a Posting Maven

Can you show us the full code, where the exception occurs?
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

... the problem which i am facing is, if the user redirects the form to another page and when comes back,
i want that the previous choices clicked ba the user is visible to him when he browses back to the previous form.

Does that means you close this form (when redirecting)?
If so, you create a property on some class, which will remember (using SET modifier) the question the user was answering for the last time.
So, when comming back to this question form, you read that property (using Get access modifier) and then set the lablels by it.
You know what I mean?

Mitja Bonca 557 Nearly a Posting Maven

You are welcome.
Iam glad you worked it out.

Mitja Bonca 557 Nearly a Posting Maven

Sure you can. Simply create new DGVcomboBox column and add or insert it to dgv columns.

DataGridViewComboBoxColumn cmbcolumn = new DataGridViewComboBoxColumn(); 
{
    cmbcolumn.Name = "cmbColumn";
    cmbcolumn.HeaderText = "combobox column"; 
    cmbcolumn.Items.AddRange(new string[] { "aa", "ac", "aacc" }); //items in comboBox
}
dataGridView1.Columns.Insert(1, cmbcolumn); //inserting comboBox into 2nd columns (colimn at index 1)
Mitja Bonca 557 Nearly a Posting Maven

There must be a space. Space must be between every single word in a query, otherwise they are meant as one.

Mitja Bonca 557 Nearly a Posting Maven

Yes, Jim is right, you cannot assign a variable (value) to a reference (when you create an instance of some class, this is called a reference to this created class instance).
So, the closest you can get it to do like Jim showed.

Mitja Bonca 557 Nearly a Posting Maven

You can do it this way:

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim couter As Integer = 1
	For i As Integer = 0 To dataGridView1.Rows.Count - 1
		If Not dataGridView1.Rows(i).IsNewRow Then
			dataGridView1("rollNo", i).Value = [String].Format("{0}-{1}", "11", System.Math.Max(System.Threading.Interlocked.Increment(couter),couter - 1).ToString().PadLeft(4, "0"C))
		End If
	Next
End Sub

The code addes values form "11-0001" to the last student in the dgv. Enumeration is by 1 up.

Mitja Bonca 557 Nearly a Posting Maven

Hi,
this link might help you out.

Mitja Bonca 557 Nearly a Posting Maven

If you are maybe wondering how to make it work, you can see into my full example code I just did (I dont fill datatable from database, but I create columns and fill it manually).

The example fully works, if you will have problems, you can try it out. On form only put a datagridview and a comboBox, for the rest the code will take care.

Code:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace Okt01_2
	Public Partial Class Form1
		Inherits Form
		Private table As DataTable
		Private tempTable As DataTable
		Public Sub New()
			InitializeComponent()
			'creating new instance of dataTable (and creating columns)
			'you create and fill table your way, this is only part of example:
			table = New DataTable()
			table.Columns.AddRange(New DataColumn() {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String))})

			table.Rows.Add(1, "A")
			table.Rows.Add(2, "B")
			table.Rows.Add(3, "A")
			table.Rows.Add(4, "B")
			table.Rows.Add(5, "A")
			table.Rows.Add(6, "C")
			table.Rows.Add(7, "C")
			table.Rows.Add(8, "A")
			'binding table to DGV:
			dataGridView1.DataSource = New BindingSource(table, Nothing)

			comboBox1.Items.AddRange(New String() {"A", "B", "C"})
			comboBox1.SelectedIndexChanged += New EventHandler(comboBox1_SelectedIndexChanged)
		End Sub

		Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
			Dim item As String = comboBox1.SelectedItem.ToString()
			Dim rows As DataRow() = table.[Select]("Name = '" + item + "'")
			tempTable = New DataTable()
			tempTable = table.Clone()
			For Each row As DataRow In rows
				tempTable.ImportRow(row)
			Next
			dataGridView1.DataSource = New BindingSource(tempTable, Nothing)
		End Sub
	End Class
End Namespace
Mitja Bonca 557 Nearly a Posting Maven

I have a better idea. Why dont you get all the data from the database at ones. And then you will not need to access to it any longer (to the database I mean). You will do all the work on the datatable, using filtering. ComboBox selected item will be serving as a filter to get vanted data (rows). This means using SELECT method od datatable.

Here, i did an example how to use it.

NOTE:
- table is a variable, which stores all your data from the database.
- tempTable is filtered data.

Private table As DataTable
Private tempTable As DataTable
Public Sub New()
	InitializeComponent()
	'creating new instance of dataTable (and creating columns)
	'you create and fill table your way, this is only part of example:
		'HERE YOU GET ALL THE DATA FROM DB using SQL QUERY:
		' ->> "select partname,partdesc,partnum,partqty from partno"
		'NO WHERE CLAUSE
	table = New DataTable()
End Sub

Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
	Dim item As String = comboBox1.SelectedItem.ToString()
	Dim rows As DataRow() = table.[Select]("Name = '" + item + "'")
	tempTable = New DataTable()
	tempTable = table.Clone()
	For Each row As DataRow In rows
		tempTable.ImportRow(row)
	Next
	dataGridView1.DataSource = New BindingSource(tempTable, Nothing)
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Hi, please check here how to use Like condition. Its all well explained.
bye

Mitja Bonca 557 Nearly a Posting Maven

Hmm, it should select only rows where type is selectedItem from comboBox.

Would you mind showing me an image of database? I means the data from it (from partno table)?

Mitja Bonca 557 Nearly a Posting Maven

Hi,
try using "ComboBox2.SelectedItem.ToString" instead.

Mitja Bonca 557 Nearly a Posting Maven

The same error: Incorrect syntax near '.'??
Please double check the correctness of table names and fields.

Mitja Bonca 557 Nearly a Posting Maven

Hmm, and where is a Timer reference? Times instantiation code?
And why are 3 if blocks (same one) needed? You only create one.
Take a look.

Full code should look like:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//for this code bellow you dont need  Threading namespace!!!

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        //Timer is from Windows.Froms namespace!
        Timer timer1;
        Login login;
        public Form1()
        {
            InitializeComponent();
            //timer instantiation:
            timer1 = new Timer();
            timer1.Interval = 1000; //every second will be called an event Tick
            timer1.Tick += new EventHandler(timer1_Tick);             
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //start timer:
            timer1.Start();    
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Increment(1);
            if (progressBar1.Value == 100)
            {
                timer1.Stop();
                progressBar1.Hide();
                this.Hide();
                login = new Login();
                login.Show();
                //I Add This As Notes in Order to Debug Without Errors
            }
        }
    }

    //login form:
     public partial class Form1 : Form
     {
          public Login()
          {
               InitializeComponent();
               MessageBox.Show("It Works, and welcome on login form!", "Welcome note.)", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
          }
     }
}
Mitja Bonca 557 Nearly a Posting Maven

Yes, you should name methods so they have a common sence. And every one can understands them. The best approach is to name them in this kind of manner, that someone who reads it, even approximatelly knows what is inside the method (the code it self).
Rename this method (GetInches) to something common to all the "dimmension common langauge", like GetUnitType() as thines proposed.

Btw, there is one more thing, if user enters a non integer value, you need to have some kind of a checking, to avoid exceprtions, like:

// This method will acquire the value in inches according to user input
        public static int GetUnitType(string whichOne)
        {
            Console.Write("Please enter in the {0}: ", whichOne);
            int intValue = 0;
            while(true)
            {
                if(!int.TryParse(Console.ReadLine(), ont intValue))
                     Console.WriteLine("Wrong format. Please re-type it.");
                else
                     break;
            }
            return int.Parse(Console.ReadLine());
        }

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

You have to know that dataTable by default has object type. No string ot integer.
So if you want to pass some integer value, you have to explicitly (or implicitly) convert it.

Mitja Bonca 557 Nearly a Posting Maven

Hi, try with this code:

private static void DrawABox( int x, int y, int width, int height,char Edge,string Message )
    {
        int LastIndex =0 ;
        Console.SetCursorPosition(x, y);
        for ( int h_i = 0; h_i <= height ; h_i++ )
        {
            if ( LastIndex != -1 )
            {
                int seaindex = (LastIndex + ( width - 1) );
                if(seaindex >= Message.Length -1 )
                    seaindex = Message.Length - 1;
                int newIndex = Message.LastIndexOf(' ',seaindex);
                if(newIndex == -1 )
                    newIndex = Message.Length - 1;
                string substr = Message.Substring(LastIndex, newIndex - LastIndex);
                LastIndex = newIndex;
                Console.SetCursorPosition(x + 1, y + h_i);
                Console.Write(substr);
            }
            for ( int w_i = 0; w_i <= width; w_i++ )
            {

                if ( h_i % height == 0 || w_i % width == 0 )
                {
                    Console.SetCursorPosition(x + w_i, y + h_i);
                    Console.Write(Edge);
                }


            }

        }
Mitja Bonca 557 Nearly a Posting Maven

:)
I am so glad if I see people I who I helped them glad.
Have a great Friday your self too.
bye, bye

Mitja Bonca 557 Nearly a Posting Maven

As I see from you code, you are doing .NET application (web application).
So CurrencyManager is out of question. It is only available in win forms. Win forms and Asp.net applications are two completel different things.
Iam not very familiar with asp.net programming (yet), so I cannot help you out here. Sorry. But you can take a look at here, or ask a question to some Asp.NET forum.
I hope you manage to work it out.

Mitja Bonca 557 Nearly a Posting Maven

nice :)

foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        string memberDT = dr[0].ToString(); //0 is the index for the 1st column, so you have to adapt the code to suit the column indexes
                        if (memeberDGV == memberDT)
                        {
                            //member already exists in dgv!
                            count++;
                        }
                    }

the same goes for the columns in the dgv. Just set the indexes or columns names, so it will check the same ones.

Mitja Bonca 557 Nearly a Posting Maven
// Position to prev Record in Customer
        private void btnPrev_Click(object sender, System.EventArgs e)
        {
            if (this.BindingContext[dsView,"Customers"].Position > 0)
            {
                this.BindingContext[dsView,"Customers"].Position--;
            }
        }

        // Position to next Record in Customer
        private void btnNext_Click(object sender, System.EventArgs e)
        {
            CurrencyManager cm = (CurrencyManager)this.BindingContext[dsView,"Customers"];
            if (cm.Position < cm.Count - 1)
            {
                cm.Position++;
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Remember, messages boxes, like you had them inside the code, will fire each row when looping through the dataTable. This is ok and normal (I reapeat, like you had them inside the loop).
I suggest you to use my code from the previos post, to notifly the user about duplications (if nothing else).

Mitja Bonca 557 Nearly a Posting Maven

Hmmm, you didn`t study that link at all. I can see that from your code.
I cannot do all the code instead of you.
Please as I told you, read all whats there on that website.

Some way points: you have to get the data from databse into DATATABLE (not directly into textboxes).
Use connection and dataAdapter classes to fill dataTable, the follow the steps from that website (you have to use controls databinding, and CurrencyManager class on those two buttons forward and backward).

Mitja Bonca 557 Nearly a Posting Maven

Hmm, what can you do?
You have to learn how to make code, right? So that means only one thing, you have to read and memorize.
Like we all had to. And when reading something, try to do an example or more of them, this way its easier to remember. As simple as that.

Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to do show the message only ONES - after the checking is all done.
So do it like:

int count = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (!row.IsNewRow) //checking for a new row
                {
                    string memeberDGV = dataGridView1[0, row.Index].Value.ToString();
                    foreach (DataRow dr in table.Rows)
                    {
                        string memberDT = dr[0].ToString();
                        if (memeberDGV == memberDT)
                        {
                            //member already exists in dgv!
                            count++;
                        }
                    }
                }
            }
            if (count > 0)
                MessageBox.Show(String.Format("{0} {1} already in the list. {2} not coppied.", count, (count == 1 ? "member" : "members"), count == 1 ? "It was" : "They were"));
Mitja Bonca 557 Nearly a Posting Maven

Sure you are keep on getting messages. For every single check of the user, no matter if its in the "list" of dgv, or not.

Do you want to show the meesage only for the user which is already in the list, or you would like to show the message only ones - on the end, which will tell "There is/are usres in the list??

Mitja Bonca 557 Nearly a Posting Maven

Ok.

Mitja Bonca 557 Nearly a Posting Maven

Sure, and its a great book. It cover everything you need to know to become a good OOP programmer.

Mitja Bonca 557 Nearly a Posting Maven

Does it work?
it should ;)

Mitja Bonca 557 Nearly a Posting Maven

Show me your whole code of this.

Mitja Bonca 557 Nearly a Posting Maven

There is plenty of books out there. Look on amazon.com
I would recommend you to get books:
- Illustrated C# 2008 (for beginners)
- C# 4.0 in a Nutshell (great books, has all) - just read it

About the coding, if you have any particular example code, where you are having issues, please paste it in here, and we`ll be glad to help you out.

Use a code block for the code!