Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • i tried but is not working not displaying in datagridview
AuthorQuestion
i tried but is not working not displaying in datagridview
Posted on: 16 Mar 2013
  In database records as follows;

Faculty Date Sess1 Sess2 Sess3 Sess4
 
RAM 1/1/2013 checkboxchecked checkboxchecked checkboxchecked checkboxchecked 
RAM 2/1/2013 checkboxchecked checkboxchecked checkboxchecked checkboxchecked
 

 
Design as follows;
 
Faculty Code combo box
 
Datagridiview as follows;
 
Date Sess1 Sess2 Sess3 Sess4
1/1/2013 checkboxchecked checkboxchecked checkboxchecked checkboxchecked
2/1/2013 checkboxchecked checkboxchecked checkboxchecked checkboxchecked
 
in run mode when i click the Faculty Code, the particular faculty code record is to be retrieved from the database and display into the datagridview.
 
For that code as follows;
 
private void cb_Faculty_Code_SelectedIndexChanged(object sender, EventArgs e)
{

int irows = 0;
try
{
sql = "Select [Available_date],[Session1],[Session2],[Session3],[Session4] from Tb_Faculty_Availability where Faculty_code = '" + cb_Faculty_Code.Text.ToString() + "'";
dr = GFun.ReadAcessSql1(sql);
while (dr.Read())
{
for (irows = 0; irows < DGVCalendar.RowCount; irows++)
{

DGVCalendar.Rows[irows].Cells[2].Value = dr[0].ToString();
DGVCalendar.Rows[irows].Cells[4].Value = dr[1].ToString();
DGVCalendar.Rows[irows].Cells[5].Value = dr[2].ToString();
DGVCalendar.Rows[irows].Cells[6].Value = dr[3].ToString();
DGVCalendar.Rows[irows].Cells[7].Value = dr[4].ToString();

}
irows++;
}
dr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
return;
}
 
In run mode when i click the combobox(Faculty code) in the datagridview the selected faculty code not displaying in the datagridview.
 
what is the problem in my above code?
 
Please help me.

Narasiman
AuthorReply
Re: i tried but is not working not displaying in datagridview
Posted on: 18 Mar 2013  

hi,

if your datagrid's column type is DataGridViewCheckBoxColumn then you pass the value by using following code

DGVCalendar.Rows[irows].Cells[2].Value = dr[0].ToString().ToLower() == "true" ? true : false;
DGVCalendar.Rows[irows].Cells[4].Value = dr[1].ToString().ToLower() == "true" ? true : false;
DGVCalendar.Rows[irows].Cells[5].Value = dr[2].ToString().ToLower() == "true" ? true : false;
DGVCalendar.Rows[irows].Cells[6].Value = dr[3].ToString().ToLower() == "true" ? true : false;
DGVCalendar.Rows[irows].Cells[7].Value = dr[4].ToString().ToLower() == "true" ? true : false;

hope this will help you.


SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.