Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
DataTable dt = blord.getitembyitem_id(Convert.ToInt32(lblitem_id.Text));
           if (dt.Rows.Count > 0)
           {
               if (dataGridView1.Rows[i].Cells[0].Value.ToString() == "")
               {
                   dataGridView1.Rows.Add();
                   dataGridView1.Rows[i].Cells[0].Value = dt.Rows[0]["item_name"].ToString();
                   dataGridView1.Rows[i].Cells[1].Value = quantity;
                   dataGridView1.Rows[i].Cells[2].Value = dt.Rows[0]["item_price"].ToString();
                   i++;
               }
               else
               {
                   dataGridView1.Rows[i].Cells[1].Value = dataGridView1.Rows[i].Cells[1].Value + 1.ToString();
               }
           }


What I have tried:

i have a problem in datagridview code, any solution
Posted
Comments
Sergey Alexandrovich Kryukov 10-Feb-16 1:49am    
No, "What I have tried" is not what you have tried...
You did not ask a single question, did not formulate any problem. How can you expect any help?
—SA
Member 12242717 10-Feb-16 1:54am    
i have a problem in if statement of datagridview.... i want to check a item_name if it in datagridview i want to add it.
Richard MacCutchan 10-Feb-16 3:58am    
What problem? Unless you explain what is not working we cannot even begin to guess what help you need.
vipan.net 10-Feb-16 4:12am    
where you facing issue in checking item_name. explain your issue in detail. No one able to understand.
Alex M.H. 10-Feb-16 18:41pm    
mmhpf. your code is missing a lot of information
- there is some kind of counter (i) but no loop
- if you want to "load" your data from the table into the grid, you better use databinding, but I'm not clear about the if condition in your code ...
- you do add a new row, but don't write any data to that new datagrid row ...
so we do need more input to help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900