Hi,I would like to do a sorting when i had add new record,the new record must shown on the top of datagridview.It will always show latest record on top of the others old records.I had try several method that found from website but still cannot work!!!
code for load database to datagridview
using (TMPB_attn_DAL dalObj = new TMPB_attn_DAL())
{
dataGridView1.DataSource = dalObj.GetRecords().Cast<TMPB_attn>().ToList();
dataGridView1.Refresh();
}
code for update new record
private void txt_proximity_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
TMPB_attn row_TMPN_attn = BusinessLogicLayer.TMS_GET_PROXIMITY_VALID_TO_USE(txt_proximity.Text);
if (row_TMPN_attn == null)
{
if (!String.IsNullOrEmpty(txt_proximity.Text))
{
using (TMPB_attn_DAL dalObj = new TMPB_attn_DAL())
{
try
{
if ((!(txt_ic.Text == string.Empty)))
{
if ((!(txt_name.Text == string.Empty)))
{
TMPB_attn row = new TMPB_attn();
row.attn_empName = txt_name.Text;
row.attn_empIC = txt_ic.Text;
row.attn_proximityNo = txt_proximity.Text;
row.attn_dateTimeIn = Convert.ToDateTime(txt_datetime.Text);
row.gen_modifyUser = SYSTEM_USER_LOGIN.UserName;
row.gen_entryUser = SYSTEM_USER_LOGIN.UserName;
row.gen_actStatus = "A";
row.attn_category = "T";
dalObj.UpdateRecord(row);
MessageBox.Show("Record Added");
txt_proximity.Text = "";
txt_ic.Text = "";
txt_name.Text = "";
txt_datetime.Text = "";
txt_proximity.Enabled = false;
loadGridView();
}
else
{
MessageBox.Show("Please try again");
txt_proximity.Text = "";
txt_ic.Text = "";
txt_name.Text = "";
txt_datetime.Text = "";
txt_proximity.Enabled = false;
}
}
else
{
MessageBox.Show("Please try again");
txt_proximity.Text = "";
txt_ic.Text = "";
txt_name.Text = "";
txt_datetime.Text = "";
txt_proximity.Enabled = false;
}
}
catch (Exception es)
{
MessageBox.Show(es.Message);
}
}
}
else
{
MessageBox.Show("Please try again");
txt_proximity.Text = "";
txt_ic.Text = "";
txt_name.Text = "";
txt_datetime.Text = "";
txt_proximity.Enabled = false;
}
}
else
{
MessageBox.Show("Proximity No. is exist");
txt_proximity.Text = "";
}
}
}
here are the code that had been put in and try before but nothing happen
dataGridView1.Sort(dataGridView1.Columns["attn_id"], ListSortDirection.Descending);