C# buttons wont work on al tabs

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 2585 Views - Last Post: 28 June 2014 - 02:08 PM Rate Topic: -----

#1 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

C# buttons wont work on al tabs

Posted 24 June 2014 - 03:04 AM

Hello i am a it hardware student, me and some other students from the same class wantend to learn some thing about c# programming we got some excersise from an teachter that teaches programming to learn the c# programming basics and something litle more advanced.

The opjective was to build an c# deskop windows application for an classic car sales company.

My job was the employees section of the application.

my problem is the following

i have 3 tabs
summary (overzicht)
details
mutation (muteren)

on the details tab i have 2 buttons and a search box both the buttons only do somthing on the summary tab where they also need to take the selected row to the field on the other tabs.

the search box is a text box that neds to find the valve in the summary tab and then als so select the full row and put it in the onther 2 tabs fields.

this is the code for the back en next buttons
    private void btnback_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow.Index >= 1)
     {
        int rowIndex = Math.Min(
                   (dataGridView1.CurrentRow.Index - 1), 
                dataGridView1.Rows.Count - 1);
        dataGridView1.CurrentCell =  
         dataGridView1.



Rows[rowIndex]
        

        .Cells[dataGridView1.CurrentCell.ColumnIndex];
            }
}

private void btnnext_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow.Index  <= 1)
       {
        int rowIndex = Math.Min(
                   (dataGridView1.CurrentRow.Index + 1),
                dataGridView1.Rows.Count +1);
        dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex].Cells[dataGridView1.CurrentCell.ColumnIndex];
  
    }     
}



here is the code for the text box
 private void textBox9_TextChanged(object sender, EventArgs e)
        {
            String searchValue = "somestring";
            int rowIndex = -1;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[1].Value.ToString().Equals(searchValue))
                {
                    rowIndex = row.Index;
                    break;
                }
            }



as i mentiond before i am no programmer just exploring the programming field this is not some homework thing for school just to get some basic and advaced points of programming.

i am dutch so my spelling check will render evry english word als faulty/bad so sorry for mis typed or word word use.

can some one please help me out with out my part the whole application will be ueseless to build.

atached you wil find the project and the database script you need it will be a .rar file within a zip file deu to upload restrictions for singel .rar files and maxiumum file size

kind regards
michel

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: C# buttons wont work on al tabs

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# buttons wont work on al tabs

Posted 24 June 2014 - 04:53 AM

You say you're not a programmer, but you are trying to program a commercial application. Why do you think you can do this without any schooling?

Are you expecting us to teach you programming in this thread so you can fix your code? Or are you expecting us to fix it for you?

Quote

on the details tab i have 2 buttons and a search box both the buttons only do somthing on the summary tab where they also need to take the selected row to the field on the other tabs.

the search box is a text box that neds to find the valve in the summary tab and then als so select the full row and put it in the onther 2 tabs fields


Are you asking us to write that functionality for you?

If you need to learning C# programming we have tutorials:
C# Learning Series, right here on DIC

If you are seeing an error in your program that you haven't told us about, we have tutorials on how to debug:

See FAQ # 2 below

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 6: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Feb 2014
Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 24 June 2014 - 05:31 AM

its not a commercial application its a made up thing from the teacher but he want al the separate parts and he wil make 1 applicaiton from al separate parts.

The problem is not that the application does noet work the onley thing that doesnt work is the buttons and the search box.

now that you mention it i forgot that the buttos wil work in the summary but will only go trough rows 1-3 and further tey wont select that may be a database related isue i didnt make it the script to create it was also made by the teacher.

i have gone trough debugging with breakpoints servral times but they doent give back any information like null valves or something.

i am sutrainly that i will go trough the programming education lvl when i am done with the hardware level.

maybe this excersice is also some kind of test to see if you can program or are willing to learn it.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# buttons wont work on al tabs

Posted 24 June 2014 - 05:41 AM

Quote

this is not some homework thing for school just to get some basic and advaced points of programming.


You earlier said this was *not* homework. Maybe something was lost in translation. Because now you are explaining that it *is* homework.

Quote

i am dutch so my spelling check will render evry english word als faulty/bad so sorry for mis typed or word word use.

You might try translate.google.com where you can type your paragraphs in Dutch then use their translation into English.

I'm also still confused about what you are asking us to do. All I'm really seeing in your post is "My homework doesn't work, fix it for me". Can you maybe rephrase what you are asking us to do?
Was This Post Helpful? 1
  • +
  • -

#5 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 24 June 2014 - 05:49 AM

teacher does not declare it as homework because we are not in the programming class we just saw him explane programming during the class in hardware technologies we aad and tought thats cool so afterwards we asked for some explanation on what he was teaching there and we wanten to learn it.

he gave us this thing and splitted it up.


The thing i am asking is how do i get the buttons to take the selected row from the summary and put in in the text fields on the details and mutaion tabs.

in the database the one key that is newver changed is the empnumber.
Was This Post Helpful? 0
  • +
  • -

#6 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 07:50 AM

ok it looks like nobody eather understands my problem or nobody can help me with it.

then i am stuck with it i think programming isn't my thing then :surrender: i think i give it up then
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,976
  • Joined: 05-May 12

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 08:41 AM

The trick here is to setup a View Model that keeps track of the current selected item. All the tabs read from the view model to determine what they should be displaying.

That view model could be as simple as a property exposed by container that holds your tab control... In this case the form.
Was This Post Helpful? 1
  • +
  • -

#8 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 09:54 AM

sorry to say this but i dont know how to do that kind of stuff

where do i start from whit that kind of programming
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 10:46 AM

Don't think of it as we don't want, or can't, help you.
But it seems like you said:

Quote

"I'm not in a programming course. We saw the teacher doing coding in a hardware course and it looked cool so we are trying to do some stuff with no background in coding. Please teach me what I need to know about coding in a single question thread."

Am I wrong about how I summarized your situation?

The simple fact is we can't tell you everything you need to know to write your program... everything from good design concept to all the syntax of the language, to the foundation concepts of MVVM... In a single thread.

Its like saying... "I looked at a building and thought it would be cool to architect a skyscraper. Tell me what I need to know to build a 10 story building."

Earlier I gave you a link to our C# learning series. The plain and simple truth is that you need to start learning from the beginning, not try to build a program with no background in development.
Was This Post Helpful? 1
  • +
  • -

#10 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 10:57 AM

i have read 2 full book about c# programming but the simple fact is even in the book i cant find this kind of application building.

i have searched the internet debugged 2 hour long and cant find where the problem resides and to top the whole of even though it doesnt have to be brought in to score points for it the teacher changed his mind beginnen of the evening and now want the parts of all of us tomorow so this is why i ask for someone with the c# knowlage to help fix the button problem that search bar i will take out of the program it isn't a feature that's verry wanted he said search bar items are lovely to have but not needed.

so its one last resort question please help me fix it.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,165
  • Joined: 12-June 08

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 11:07 AM

Quote

so its one last resort question please help me fix it.

Be cognizant of the rules regarding asking folks to do the work for you.
Was This Post Helpful? 1
  • +
  • -

#12 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 25 June 2014 - 12:09 PM

i the beginning it was just a question to point me in the right direction until my teacher suddenly changed his mind and wantend all the part tomorrow i am just a beginning programmer and cant program such a problem out in just 1 day so my last resort was the internet searched for it coudent find any thing that helped me out then this site wa my last resort to turn to to ask for help to fix it.

I am not asking for you to fix all of it just point out to me whats the best methodes and why i atached the project it self so you could look trough it all maybe i missed some where else better to give more then less i was always told.
Was This Post Helpful? 0
  • +
  • -

#13 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 27 June 2014 - 04:24 AM

teacher realy doesnt know what he wants now the project need a button that does the following

the seceted datagridview1 row or selected cell valave need to be taken to an multiline text field by a button
 had changed the code but it give back this exception 
The index is out of range. These must not be negative and must be less than the size of the collection.


private void selectedCellsButton_Click(object sender, EventArgs e)

       {

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empNumber"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empLastName"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empFisrtName"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empExtension"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empemail"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empOfficeCode"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empReportsTo"].Value.ToString();

           Cvalve.Text = dataGridView1.SelectedRows[0].Cells["empJobTitle"].Value.ToString();

       }

 

i cant seen to find a way to get past this exception

maybe someone here cant point me in the right direction what is causing this exception so i can find the right way to fix it.
Was This Post Helpful? 0
  • +
  • -

#14 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# buttons wont work on al tabs

Posted 27 June 2014 - 05:26 AM

Quote

The index is out of range.

That means you tried to get item 4 from a 3 item collection, for example. Your index (of 4) was out of the range of 0-2

If you're trying to get selectedRows element 0, and there are no selected rows, then you're trying to get something out of the range.

Quote

just point out to me whats the best methodes

The debugging tutorials we pointed you to *are* the best methods. There is no magic tool that will point out the problem. You have to combine comprehension and hard work to find bugs.
What does this error message mean?

Its not easy. And its not fast. But debugging is about checking every little tiny detail, every variable value and walking each and every line of suspect code. COMBINED WITH, knowing what *should* be happening and what *should* be the values you expect and confirming that are the actual values.

One I thing I pointed out in that debugging tutorial is that complex lines like this one should be broken down to confirm every part.
dataGridView1.SelectedRows[0].Cells["empExtension"].Value.


SelectedRows[0] might have a value, but you don't check to confirm it.
Even if it does have a value getting .Cells["empExtension"] is not guaranteed to have a value, but you don't check. So by the time you try to get the .Value of a cell that may or may not exist there are a couple points of possible error. You have to be more robust in your checking.

if (dataGridView1.SelectedRows.Count > 0)
{
     var selected = dataGridView1.SelectedRows[0];
     if (selected != null)
     {
          //Now get the cell
          if (theCell != null)
          {   
             //Now get the value
          }
     }
}


You say you are looking for better methods and advice, but the fact is the tutorials we pointed you to show this technique. I don't think you are looking for 'better' methods so much as looking for 'faster' or more automatic methods that don't require so much boring step-by-step work on your part. You need to accept that a large part of this job is paying attention to, and verifying every last tiny detail.
Was This Post Helpful? 1
  • +
  • -

#15 sojab0on   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 24-June 14

Re: C# buttons wont work on al tabs

Posted 27 June 2014 - 05:46 AM

ok your point out worked up until i got back to the cant find colum exception
Cant find column with name empnumber .

This may be because the data grid get filled by a data binding source, but dont get the error : could not find column with name. because the grid view shows the columns with exactly those names, even in the database the columns are called exactly the same.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3