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

Lookup pod filterom u gridu?

[es] :: .NET :: Lookup pod filterom u gridu?

[ Pregleda: 1687 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Predrag Supurovic
Pedja YT9TP
Užice

Član broj: 157129
Poruke: 6279

Sajt: pedja.supurovic.net


+1571 Profil

icon Lookup pod filterom u gridu?13.05.2010. u 17:30 - pre 169 meseci
Radim u C#. Primera radi imam ove dve tabele:


DRZAVE
- ID_DRZAVE (PK)
- NAZIV

MESTA
- ID_MESTA (PK)
- ID_DRZAVE
- NAZIV


Hocu da prilikom unosa podataka u neku trecu tabelu, kroz grid, korisnik ima mogucnost da dok unosipodatek uslog, izabere drzavu kroz combobox a da onda izabere mesto iz spiska mesta takodje u combobox, ali filtriranog samo na mesta koja spadaju u izabranu drzavu.

Kako ovo da izvedem?



 
Odgovor na temu

Sapphire
Denis Biondić
.NET software developer
Nürnberg, Germany

Član broj: 213086
Poruke: 290
62.113.3.*



+6 Profil

icon Re: Lookup pod filterom u gridu?13.05.2010. u 18:07 - pre 169 meseci
Na najnižem nivou solucija ti je da staviš logiku punjenja ćelije sa gradovima svaki put kad se combobox sa državom promijeni, ali opet, to nije baš najbolje rješenje. WinForms Data Binding je prilično moćan za slične situacije, evo pogledaj ovo:

http://www.akadia.com/services/dotnet_databinding.html

Prođi taj tutorial, biće ti mnogo sve jasnije...
My programs don’t have bugs, they just develop random features.
 
Odgovor na temu

ravni

Član broj: 8894
Poruke: 373



+15 Profil

icon Re: Lookup pod filterom u gridu?14.05.2010. u 22:58 - pre 169 meseci
iz FAQ - DataGridView Control
http://www.windowsclient.net/S...ridView/DataGridView%20FAQ.doc
Citat:

18. How do I have a combo box column display a sub set of data based upon the value of a different combo box column?
Sometimes data that you want to display in the DataGridView has a relationship between two tables such as a category and subcategory. You want to let the user select the category and then choose between a subcategory based upon the category. This is possible with the DataGridView by using two combo box columns. To enable this, two versions of the filtered list (subcategory) needs to be created. One list has no filter applied while the other one will be filtered only when the user is editing a subcategory cell. Two lists are required due to the requirement described in 3.5.1 section that a combo box cells value must be in the items collection or else a DataError event is raised. In this case, since all combo box cells in the column use the same datasource if you filter the datasource for one row then a combo box cell in another row might not have its value visible in the datasource, thus causing a DataError event.

The below example uses the Northwind database to display related data from the Territory and Region tables (a territory is in a specific region.) Using the category and subcategory concept, the Region is the category and the Territory is the subcategory.

Code:
private void Form1_Load(object sender, EventArgs e)
{
    this.territoriesTableAdapter.Fill(this.northwindDataSet.Territories);
    this.regionTableAdapter.Fill(this.northwindDataSet.Region);

    // Setup BindingSource for filtered view.
    filteredTerritoriesBS = new BindingSource();
    DataView dv = new DataView(northwindDataSet.Tables["Territories"]);
    filteredTerritoriesBS.DataSource = dv;

}

private void dataGridView1_CellBeginEdit(object sender,
         DataGridViewCellCancelEventArgs e)
{
    if (e.ColumnIndex == territoryComboBoxColumn.Index)
    {
        // Set the combobox cell datasource to the filtered BindingSource
        DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1
                        [e.ColumnIndex, e.RowIndex];
        dgcb.DataSource = filteredTerritoriesBS;

        // Filter the BindingSource based upon the region selected
        this.filteredTerritoriesBS.Filter = "RegionID = " +
            this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
    }
}

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == this.territoryComboBoxColumn.Index)
    {
        // Reset combobox cell to the unfiltered BindingSource
        DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1
                        [e.ColumnIndex, e.RowIndex];
        dgcb.DataSource = territoriesBindingSource; //unfiltered

        this.filteredTerritoriesBS.RemoveFilter();
    }
}

 
Odgovor na temu

[es] :: .NET :: Lookup pod filterom u gridu?

[ Pregleda: 1687 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

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