Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

C# DataGridView Event Problem

[es] :: .NET :: .NET Desktop razvoj :: C# DataGridView Event Problem

[ Pregleda: 632 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nexxogen
Beograd/Bar

Član broj: 90685
Poruke: 22
*.crnagora.net.

Sajt: www.dream-theater.com


Profil

icon C# DataGridView Event Problem08.08.2011. u 19:28 - pre 653 dana i 9h

Imam problem za koji nisam uspio da nađem rešenje na netu. Koristim DataGridView za prikaz i manipulaciju podacima iz baze. Imam kolonu "Konto" u kojoj imam petocifrenu ili šestocifrenu šifru koju dovlačim iz baze i na osnovu koje treba da popunim još tri kolone: "Nivo I", "Nivo II" i "Nivo III" i to tako što će Nivo I da sadrži prvu cifru konta, Nivo II prve dvije cifre, a Nivo III prve tri cifre. Problem se sastoji u tome što ne znam kako da pokrenem CellEndEdit event SAMO ZA KOLONU Konto! Ono što ja zovem se odnosi na sve kolone čija se vrijednost mijenja što naravno ne može tako da stoji zbog bespotrebnog trošenja resursa kao i zbog drugih problema.

Prostije rečeno, kako se pokreće neki DataGridView Event (konkretno CellEndEdit) samo za pojedinačnu kolonu, a ne za sve kolone?

Da li neko može da mi pomogne?
Just becouse you said it, doesn't make it so!
 
Odgovor na temu

Igor Gajic
Novi Sad

Član broj: 93194
Poruke: 724
*.dynamic.isp.telekom.rs.

Sajt: www.flickr.com/photos/igo..


Profil

icon Re: C# DataGridView Event Problem08.08.2011. u 19:35 - pre 653 dana i 9h
Kada se pokrene CellEndEdit proveri da li je sender kolona Konto, ako jeste onda izvrsis logiku, ako nije nikom nista
When a government is dependent upon bankers for money, they and not the leaders of the government control the situation, since the hand that gives is above the hand that takes …

Stay smart, stay out of debt, and risk being boring

Pruske vrline
 
Odgovor na temu

nexxogen
Beograd/Bar

Član broj: 90685
Poruke: 22
*.crnagora.net.

Sajt: www.dream-theater.com


Profil

icon Re: C# DataGridView Event Problem08.08.2011. u 19:55 - pre 653 dana i 9h
Laptopovi

Hvala na odgovoru. Na žalost ovo mi još nije riješilo problem.

Kompajler vidi DataGridView kao sender, a ne specifično polje koje se edituje. :(
Just becouse you said it, doesn't make it so!
 
Odgovor na temu

nexxogen
Beograd/Bar

Član broj: 90685
Poruke: 22
*.crnagora.net.

Sajt: www.dream-theater.com


Profil

icon Re: C# DataGridView Event Problem08.08.2011. u 20:11 - pre 653 dana i 9h
Snašao sam se. :)

Hvala, ovo mi je svakako pomoglo.
Just becouse you said it, doesn't make it so!
 
Odgovor na temu

Igor Gajic
Novi Sad

Član broj: 93194
Poruke: 724
*.mts.telekom.rs.

Sajt: www.flickr.com/photos/igo..


Profil

icon Re: C# DataGridView Event Problem08.08.2011. u 20:24 - pre 653 dana i 9h
Code (csharp):

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;
            DataGridViewColumn column = dgv.Columns[e.ColumnIndex];
            if (column.Name.Equals("Konto"))
            {
                string text = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string;

                if (!String.IsNullOrEmpty(text) && text.Length >= 3)
                {
                    dgv.Rows[e.RowIndex].Cells["Nivo1"].Value = text.Substring(0, 1);
                    dgv.Rows[e.RowIndex].Cells["Nivo2"].Value = text.Substring(0, 2);
                    dgv.Rows[e.RowIndex].Cells["Nivo3"].Value = text.Substring(0, 3);
                }
            }
        }
 



When a government is dependent upon bankers for money, they and not the leaders of the government control the situation, since the hand that gives is above the hand that takes …

Stay smart, stay out of debt, and risk being boring

Pruske vrline
 
Odgovor na temu

AMD guy
Miroslav Bučko
.NET developer

Član broj: 128930
Poruke: 798
*.dynamic.isp.telekom.rs.

Sajt: www.its.edu.rs


Profil

icon Re: C# DataGridView Event Problem09.08.2011. u 12:37 - pre 652 dana i 16h
jel mozes da mi objasnis ova tri reda
Code (csharp):
DataGridView dgv = (DataGridView)sender;
            DataGridViewColumn column = dgv.Columns[e.ColumnIndex];
            if (column.Name.Equals("Konto"))

 
Odgovor na temu

nexxogen
Beograd/Bar

Član broj: 90685
Poruke: 22
*.crnagora.net.

Sajt: www.dream-theater.com


Profil

icon Re: C# DataGridView Event Problem09.08.2011. u 12:38 - pre 652 dana i 16h
@ Igor Gajić

Ja sam to malo drugačije, al hvala u svakom slučaju.

Mada, sad me zaintrigira... Zašto praviš novi dgv i zašto castuješ sender u dgv, kad je on to već?
Just becouse you said it, doesn't make it so!
 
Odgovor na temu

Igor Gajic
Novi Sad

Član broj: 93194
Poruke: 724
82.117.203.*

Sajt: www.flickr.com/photos/igo..


Profil

icon Re: C# DataGridView Event Problem09.08.2011. u 13:00 - pre 652 dana i 16h
@nexxogen
U pitanju je samo referenca, tako da se ne kreira novi objekat u memoriji, a kod je citljiviji...

@AMD guy

1. Kreiram referencu na sender, odnosno na DataGridView u kome se desio dogadjaj
2. Uzimam kolonu u kojoj se nalazi celija koja je ispalila event, na osnovu e.ColumnIndex
3. Proveravam da li je to 'Konto' kolona.
When a government is dependent upon bankers for money, they and not the leaders of the government control the situation, since the hand that gives is above the hand that takes …

Stay smart, stay out of debt, and risk being boring

Pruske vrline
 
Odgovor na temu

[es] :: .NET :: .NET Desktop razvoj :: C# DataGridView Event Problem

[ Pregleda: 632 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.