i am facing a problem
i have a class
public class StudentDetails
{
int S_Detail_ID;
string address;
string email;
}
containg get set method and iam calling a function which is collecting the List<StudentDetails>
and showing it in datagridview the problem is that list is returning all properties of the class, but i only want address and email not s_detail_id
here is code for the function
private void btnAddNewRowInGrid_Click(object sender, EventArgs e)
{
List<StudentDetails> lstStudentDetails = GetStudentDetails();
lststudentDetails.Add(new StudentDetails()); //what to do here, studentDetails is returning all properties but i want only addres and email
dataGridView1.DataSource = lstStudentDetails;
}
and GetStudent jusst count rows in datagridview and add a new row
private List<StudentDetails> GetStudentDetails()
{
lstStudentDetails = new List<StudentDetails>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
lstStudentDetails.Add(row.DataBoundItem as StudentDetails);
}
return lstStudentDetails;
}
You cannot turn off columns auto-generation from designer - its possible only from code:
dataGridView1.AutoGenerateColumns = false;
After that your code will work.
您可以通过将可见性设置为false来尝试隐藏不需要的列。
dataGridView1.Columns["S_Detail_ID"].Visible = false;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.