Hi to all experts, i have a big problem here, i want to print data from my datagridview, when i select 1 row.. there is no problem, but when i try to print multiple row, just first selected row appear
here is the code :

private void button4_Click(object sender, EventArgs e)
        {
            ReportDocument report = new ReportDocument();
            report.Load("katalogbarang.rpt");
            if (Kodetxt.Text == "")
            {

            }
            else
            {
                report.RecordSelectionFormula = "{katalog.id}= " + dg1.SelectedRows[0].Cells[9].Value + "";
            }
            PrintReport rpt = new PrintReport();
            rpt.crystalReportViewer1.ReportSource = report;
            rpt.crystalReportViewer1.Refresh();
            rpt.ShowDialog();
        }

this is my little condition

-------------------------------------------

|kodebarang | namabarang | jumlah | harga |

|0121 | kolor | 3 | 2000 |
|0892 | panci | 1 | 10000 |
|9200 | kutang | 2 | 20000 |
|8989 | cangcut | 8 | 2500 |

|7890 | sapu | 1 | 3000 |

when im selecting one row (left click)

|0121 | kolor | 3 | 2000 |

or when i randomly click (in condition i just click one row) there is no problem,
then i chose randomly and more than just one row, but which appear in crystal report only the first i click

i want report in my crystal report are like this

|9200 | kutang | 2 | 20000 |
|0892 | panci | 1 | 10000 |

or

|7890 | sapu | 1 | 3000 |
|0121 | kolor | 3 | 2000 |
|9200 | kutang | 2 | 20000 |

please someone help me... give me some code and tutorial to resolve my prob
thanks in advance

Hi Iin, welcome to daniweb. :)
First of all, I'm not an expert. An expert is someone who has made all the possible mistakes. I'm not even halfway...

In your code, you don't seem to loop through your selected cells. Here is an example on how to do that.
Hope it helps.

thanks for the reply sir,
but I was so caught up in this situation, is there any example more relevant to the situation that I experienced ??
on link that you gave, I am so confused where to start? Can you teach me a little bit sir?

when i select like this :
gbr1.png

there is no problem,

but when i select row like this:
gbr2.png

it cannot sent to crystalreport

Don't know much about cristal reports.
But what I was trying to say was:
You got to have some kind of loop:

foreach ( DataGridViewRow R in myDGV.SelectedRows)
{
//do something
}

//or
for (int i =0; i < myDGV.SelectedRows.Count; i++)
{
//do something
}

tq sir, you are my hero.... you open my mind sir... tq tq tq very much...
problem is resolve now

Glad to be of help. That's what we're here for.
Perhaps you could mark this thread solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.