가능한 중복 :
Putting a .txt file into a DataGridView.txt 파일을 DataSource에 저장하는 방법은 무엇입니까?
내가 오픈 버튼을 클릭하면 내가 파일을 선택하고 DataGridView
으로 작업 할 학습과하는 DataSource
에 배치하고 싶습니다.
오른쪽 지금은이 같은 모습을 가지고있는 : DataSource
와 매우 익숙
Title1 Title2 Title3 Title4 Title5 Title6
abc123 abc123-123-123 225.123 123.456 180 thing99
c123 somethingHERE 987.123 123.456 360 anotherThing1
abc124 somethingHERE225.123 123.456 0 thing99
은 내가 : 여기
OpenFileDialog openFile = new OpenFileDialog();
openFile.DefaultExt = "*.txt";
openFile.Filter = ".txt Files|*.txt";
openFile.RestoreDirectory = true;
try
{
if (openFile.ShowDialog() == DialogResult.OK && openFile.FileName.Length > 0)
{
// Right now I am loading the file into a RichTextBox
openFileRTB.LoadFile(openFile.FileName, RichTextBoxStreamType.PlainText);
// What I would like to do is load it into a DataSource and then into a DataGridView.
// So really I would like to remove the openFileRTB line of code and replace it.
// That is where I need help :).
}
}
catch (Exception)
{
MessageBox.Show("There was not a specified file path to open.", "Path Not Found Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
내가 개방 될 수있는 파일 (공간 분리)의 예입니다
DataGridView
그래서 어떻게 작동하는지, 어떤 일이 일어나야하는지, 어떻게 보일 지 등 크게 도움이 될만한 도움을 얻을 수 있다면. :)
감사합니다.
당신은 생성하는 모든 행/열 선 루프를 분할 할 수
_ "into DataSource"_? 그게 정확히 무슨 뜻이야? – stakx
@Stakx : 글쎄, IBindingSource를 사용하여 txt 파일에서 DataGridView를 채울 수 있습니다. – theNoobGuy
@theNoobGuy, 'IBindingSource'는 컨테이너가 아닙니다. 당신은 아무것도 넣을 수 없습니다. 대신 자신의 'DataSource' 속성이 설정되어야합니다. 즉, 데이터가 다른 곳 (예 :'DataTable ')으로 이동해야합니다 (링크 된 질문 참조). 따라서 'IBindingSource'는 데이터 소스가 아니라 다른 데이터 소스의 어댑터 또는 장식 자와 유사합니다. – stakx