Requirement : combobox having list of records (employee names) from database table say-'nworksuser' and list along with checkbox (for selection). Depending on selection(Multiple/Single/All) mode I need to display records in datagrid view from all related table(one to one / one to many).
Xaml :
<ComboBox Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="2" Grid.RowSpan="2" Height="30" Name="comboBox_Employee" >
</ComboBox>
<DataGrid Grid.Column="1" Grid.Row="5" Grid.ColumnSpan="11" Grid.RowSpan="15" Name="Datagrid_AttendanceLog"/>
.cs to fill combobox :
public partial class AttendanceLog : Window
{
string LiveUser;
public AttendanceLog(string LiveUser)
{
InitializeComponent();
this.LiveUser = LiveUser;
FillComboEmpName();
}
void FillComboEmpName()
{
int eno;
MySqlConnection conn4;
conn4 = new MySqlConnection("server=localhost;uid=root;database=newcompanydatabase;pwd=Admin@123;");
string Query = "select * from nWorksUser where _type='Employee' or _type='Admin_Employee';";
MySqlCommand cmd2 = new MySqlCommand(Query, conn4);
try
{
conn4.Open();
MySqlDataReader rdr;
rdr = cmd2.ExecuteReader();
while (rdr.Read())
{
string user = rdr.GetString("Username");
comboBox_Employee.Items.Add(user);
}
}
}
how to add checkbox for every record and code behind to display related records in datagrid view?
Aucun commentaire:
Enregistrer un commentaire