Extended Posted May 14, 2016 Share Posted May 14, 2016 Arkadaşlar okul için bir proje yapmaya çalışıyorum baya ilerledim fakat bir yerde takıldım. Main class'ımda ana ekranım var ve DataGridView im var. Bir butonla başka bir form açtırıyorum ve ordan kategori seçtiriyorum. Tamam a basınca database e bakıp o kategorideki verileri listelicem. Takıldığım nokta şu, başka class da olduğum için DataGridView imi göremiyorum ona nasıl erişim sağlayıp değişiklik yaptırabilirim? Quote Link to comment Share on other sites More sharing options...
WolfmanTR_ Posted May 14, 2016 Share Posted May 14, 2016 (edited) public yaparsan heryerden erişirsin Properties > Modifiers > "Public" Şu şekilde de çağırırsın: Form2 frm2 = new Form2(); frm2.show(); this.hide(); frm2.datagridview1..........; Edited May 14, 2016 by WolfmanTR_ Quote Link to comment Share on other sites More sharing options...
Extended Posted May 14, 2016 Author Share Posted May 14, 2016 Demin aklıma geldi Main asda = new Main(); asda.ListePaneli.Rows.Add(0,"dsfsdf"); rastgele denedim ekleme yapmadı. Quote Link to comment Share on other sites More sharing options...
WolfmanTR_ Posted May 14, 2016 Share Posted May 14, 2016 53 dakika önce, Extended yazdı: Demin aklıma geldi Main asda = new Main(); asda.ListePaneli.Rows.Add(0,"dsfsdf"); rastgele denedim ekleme yapmadı. asda. yaptığında . ya basınca ListePaneli çıkıyor mu ? çıkmıyor ise tanıtamamışsındır. Quote Link to comment Share on other sites More sharing options...
Extended Posted May 14, 2016 Author Share Posted May 14, 2016 Çıkıyor. Hata vermiyor ama eklemiyorda. Dediğin gibi yaparsam da yeni GUI eklemiş oluyorum ama direk üzerinde eklemek istiyorum ben. Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted May 15, 2016 Editor Share Posted May 15, 2016 Main frmMain = Application.OpenForms["Main"]; frmMain.datagrid.rows.add(0,"123456"); Boyle denermisiniz formunuzu main olarak kabul ettm Quote Link to comment Share on other sites More sharing options...
Extended Posted May 15, 2016 Author Share Posted May 15, 2016 (edited) Application.OpenForms["Main"]; bu kısım için, Severity Code Description Project File Line Suppression State Error CS0266 Cannot implicitly convert type 'System.Windows.Forms.Form' to 'OnlineYukleyici.Main'. An explicit conversion exists (are you missing a cast?) hatası veriyor. Edited May 15, 2016 by Extended Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 15, 2016 Share Posted May 15, 2016 şu şekilde erişebilirsiniz: Form frm1 = Application.OpenForms["Form1"]; // form1 e eriş // form1'deki kontrollere eriş foreach (Control item in frm1.Controls) { // eğer sıradaki kontrol datagridview ise if (item is DataGridView) { // bir tablo oluştur DataTable data = new DataTable(); data.Columns.Add("col1"); data.Columns.Add("col2"); data.Columns.Add("col3"); // tabloya veriler ekle for (int i = 0; i < 100; i++) { Random rnd = new Random(); data.Rows.Add(i.ToString(), rnd.Next(123456, 987654), rnd.Next(123456, 987654)); } // item'i datagridview'e çevir DataGridView dgv = (DataGridView)item; dgv.DataSource = data; // datasource ata } } https://yadi.sk/d/S4ur2uW4ricg7 2 Quote Link to comment Share on other sites More sharing options...
Extended Posted May 15, 2016 Author Share Posted May 15, 2016 Yukarida Application.OpenForms yazdigim zaman aldigim hatayi gostermistim hocam acaba main uzerinde bi ayar mi yapmam gerekiyor erisim saglamak icin? Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 15, 2016 Share Posted May 15, 2016 Bahsettiğiniz hata Application.OpenForms[index] Form türünde olduğu için hata veriyor, onu Main'e çeviremiyor, yukarıdaki verdiğim kodu Form frm1 = Application.OpenForms["Form1"]; yerine Form frm1 = Application.OpenForms["Main"]; yazarsanız projenizde kullanabilirsiniz. 1 Quote Link to comment Share on other sites More sharing options...
Extended Posted May 15, 2016 Author Share Posted May 15, 2016 Anladım hocam da bu şekilde boş olan gridview doluyor peki ya dolusunun altına eklemeyi nasıl yapıcaz? Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 15, 2016 Share Posted May 15, 2016 dgv.Rows.Add("veri", "veri2"); yukarıda vermişsiniz zaten, aynı şekilde. 1 Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted May 15, 2016 Editor Share Posted May 15, 2016 Please register to see this content. 1 Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 15, 2016 Share Posted May 15, 2016 Ha illa Form1 olarak atayacam diyosun yani pairs 2 Quote Link to comment Share on other sites More sharing options...
Extended Posted May 15, 2016 Author Share Posted May 15, 2016 pairs tam da istediğim buydu işte sağolasın Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.