0% found this document useful (0 votes)
2 views3 pages

Binding Data

This document provides a guide on how to bind data and navigate between pages in a C# WinForms application using DevExpress. It covers data binding for various controls like `GridControl`, `TextEdit`, and `ChartControl`, as well as methods for navigating between pages using `XtraTabControl` or panel switching. Additionally, it includes examples for adding and deleting data dynamically through button actions.

Uploaded by

ramsondan783
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Binding Data

This document provides a guide on how to bind data and navigate between pages in a C# WinForms application using DevExpress. It covers data binding for various controls like `GridControl`, `TextEdit`, and `ChartControl`, as well as methods for navigating between pages using `XtraTabControl` or panel switching. Additionally, it includes examples for adding and deleting data dynamically through button actions.

Uploaded by

ramsondan783
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

To bind data and navigate between pages using buttons in a C# WinForms application

with DevExpress, follow these steps

---

### 1. Setting Up Data Binding in WinForms (DevExpress)


Data binding allows UI controls like `GridControl`, `TextEdit`, and `ChartControl`
to automatically update based on a data source (e.g., a database, list, or object).

#### Example Binding a `GridControl` to a List


```csharp
public partial class Form1 Form
{
public Form1()
{
InitializeComponent();
LoadData();
}

private void LoadData()


{
ListEmployee employees = new ListEmployee
{
new Employee { ID = 1, Name = John Doe, Age = 30, Department = IT },
new Employee { ID = 2, Name = Jane Smith, Age = 25, Department = HR }
};

gridControl1.DataSource = employees;
}
}

public class Employee


{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Department { get; set; }
}
```
💡 DevExpress `GridControl` automatically detects the properties and displays them
in the grid.

---

### 2. Binding UI Controls to Data


#### TextBox (`TextEdit`) Data Binding
```csharp
bindingSource1.DataSource = employees;
textEdit1.DataBindings.Add(Text, bindingSource1, Name);
```

#### Chart Control Data Binding


```csharp
chartControl1.DataSource = employees;
chartControl1.Series[0].ArgumentDataMember = Name;
chartControl1.Series[0].ValueDataMembers.AddRange(new string[] { Age });
```

---
### 3. Navigating Between Pages Using Buttons
For multi-page navigation, use `XtraTabControl` or `Panel` switching.

#### Option 1 Using `XtraTabControl` (Best for Tab-Based UI)


1. Add an `XtraTabControl` to your form.
2. Use buttons to navigate
```csharp
private void btnNext_Click(object sender, EventArgs e)
{
if (xtraTabControl1.SelectedTabPageIndex xtraTabControl1.TabPages.Count - 1)
{
xtraTabControl1.SelectedTabPageIndex++;
}
}

private void btnPrevious_Click(object sender, EventArgs e)


{
if (xtraTabControl1.SelectedTabPageIndex 0)
{
xtraTabControl1.SelectedTabPageIndex--;
}
}
```

#### Option 2 Switching Panels Manually


```csharp
panel1.Visible = true;
panel2.Visible = false;

private void btnShowPanel2_Click(object sender, EventArgs e)


{
panel1.Visible = false;
panel2.Visible = true;
}
```

---

### 4. Connecting Buttons to Perform Actions


#### Example Add New Employee to Grid
```csharp
private void btnAdd_Click(object sender, EventArgs e)
{
var employeeList = (ListEmployee)gridControl1.DataSource;
employeeList.Add(new Employee { ID = 3, Name = New Employee, Age = 28,
Department = Finance });
gridControl1.RefreshDataSource(); Refresh the grid
}
```

#### Example Delete Selected Row


```csharp
private void btnDelete_Click(object sender, EventArgs e)
{
int selectedRowHandle = gridView1.FocusedRowHandle;
if (selectedRowHandle = 0)
{
gridView1.DeleteRow(selectedRowHandle);
}
}
```

---

### Conclusion
With DevExpress in C# WinForms, you can
✅ Bind data to `GridControl`, `TextEdit`, `ChartControl`, etc.
✅ Implement page navigation using `XtraTabControl` or `Panel` switching.
✅ Use buttons to add, delete, and modify data dynamically.

Would you like me to help structure a full project with CRUD operations 🚀

You might also like