Hi Vinnijian and All Helpers
Yeee...Haa.......Finally I got the script working. Thanks to you guys for sharing your knowledge with me. You guys and this FORUM are awesome
I would like to post the script here to share with newbie like me facing the same problems:
private void FLoadDataGrid()
{
try
{
string strSql = "Select FirstName, LastName from TblCustomer ";
sqlConn = new SqlConnection(connStr);
sqlConn.Open();
DA = new SqlDataAdapter(strSql, sqlConn);
DS = new DataSet("DS");
//Clear dataset before refill
DS.Clear();
DS.CaseSensitive = true;
DA.Fill(DS,"PatientTbl");
//declare datatable
DataTable DT = new DataTable();
DT.Clear();
DT = DS.Tables[0];
DataColumn colNewDGCol = new DataColumn();
colNewDGCol.DataType = System.Type.GetType("System.Boolean");
colNewDGCol.DefaultValue = false;
colNewDGCol.ColumnName = ("Selected");
DT.Columns.Add(colNewDGCol);
//... file datagrid
FFormatDataGridColumn();
dataGrid1.DataSource = DT;
}
catch (Exception Ex)
{
MessageBox.show(Ex.Message);
}
finally
{
sqlConn.Close();
}
}
/* ------------------------------------------------------------------ */
private void FFormatDataGridColumn()
//define column structure for datagrid
{
// declare tablestyle
DataGridTableStyle DGStyle;
DGStyle = new DataGridTableStyle();
DGStyle.MappingName = "PatientTbl";
//checkbox column
DataGridBoolColumn chkboxCol = new DataGridBoolColumn();
chkboxCol.MappingName = "Selected";
chkboxCol.HeaderText = "";
chkboxCol.Width = 50;
DGStyle.GridColumnStyles.Add(chkboxCol);
//Firstname textbox column
DataGridColumnStyle colFName = new DataGridTextBoxColumn();
colFName.MappingName = "FirstName";
colFName.HeaderText = "First Name";
colFName.Width = 150;
DGStyle.GridColumnStyles.Add(colFName);
//lastName textbox column
DataGridColumnStyle colLName = new DataGridTextBoxColumn();
colLName.MappingName = "LastName";
colLName.HeaderText = "Last Name";
colLName.Width = 150;
DGStyle.GridColumnStyles.Add(colLName);
// add table style to the dataGrid
this.dataGrid1.TableStyles.Add(DGStyle);
}
THANKS TO ALL OF YOU.